September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -3,9 +3,9 @@ defmodule Dutch_national_flag do
|
|||
defp ball(:white), do: 2
|
||||
defp ball(:blue), do: 3
|
||||
|
||||
@color {:red, :white, :blue}
|
||||
defp random_ball, do: elem(@color, :rand.uniform(3)-1)
|
||||
defp random_ball(n), do: (for _ <- 1..n, do: random_ball)
|
||||
defp random_ball, do: Enum.random([:red, :white, :blue])
|
||||
|
||||
defp random_ball(n), do: (for _ <- 1..n, do: random_ball())
|
||||
|
||||
defp is_dutch([]), do: true
|
||||
defp is_dutch([_]), do: true
|
||||
|
|
@ -13,7 +13,8 @@ defmodule Dutch_national_flag do
|
|||
defp is_dutch(_), do: false
|
||||
|
||||
def dutch(list), do: dutch([], [], [], list)
|
||||
defp dutch(r, w, b, []), do: r ++ w ++ b
|
||||
|
||||
defp dutch(r, w, b, []), do: r ++ w ++ b
|
||||
defp dutch(r, w, b, [:red | list]), do: dutch([:red | r], w, b, list)
|
||||
defp dutch(r, w, b, [:white | list]), do: dutch(r, [:white | w], b, list)
|
||||
defp dutch(r, w, b, [:blue | list]), do: dutch(r, w, [:blue | b], list)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue