Created
November 14, 2020 06:30
-
-
Save okabe-yuya/86ac7b0519dd03b0c2c67dcf15c6f8ce to your computer and use it in GitHub Desktop.
クリスマスプレゼント交換会にElixirで備える
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
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