Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
クリスマスプレゼント交換会にElixirで備える
defmodule SecretSanta do
def static_solver, do: static_member() |> _solver()
def random_solver, do: random_member() |> _solver()
defp _solver(lst) do
lst |> Enum.shuffle() |> print_result()
end
defp static_member, do: ["tomoya", "nagisa", "kyou", "ryou", "tomoyo", "kotomi"]
defp random_member, do: Enum.map(1..100, fn n -> "mr_#{n}" end)
defp template_print(from, to), do: IO.puts("#{from} => #{to}")
defp print_result([h | _] = lst), do: _print_result(lst, h)
defp _print_result([], _), do: :ok
defp _print_result([h | []], first) do
template_print(h, first)
_print_result([], first)
end
defp _print_result([h | t], first) do
next = Enum.at(t, 0)
template_print(h, next)
_print_result(t, first)
end
end
SecretSanta.random_solver()
SecretSanta.static_solver()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.