Created
November 5, 2020 21:01
-
-
Save Sh4pe/75352fa6906aef959d083f308080da1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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