Skip to content

Instantly share code, notes, and snippets.

@Sh4pe
Created November 5, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sh4pe/75352fa6906aef959d083f308080da1a to your computer and use it in GitHub Desktop.
Save Sh4pe/75352fa6906aef959d083f308080da1a to your computer and use it in GitHub Desktop.
import Random
function generate_pairs(names)
while true
candidates = zip(names, Random.shuffle(names)) |> collect
# Only take those permutations without fixed point, i.e.
# noone has to buy a present for herself/himself
if findfirst(p -> p[1] == p[2], candidates) === nothing
return candidates
end
end
end
function print_present_giving(pairs)
for p in pairs
println("$(p[1]) beschenkt $(p[2])")
end
end
# Place your real friends here
names = ["person1", "person2", "person3"]
# Now print who has to buy presents for whom
names |> generate_pairs |> print_present_giving
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment