diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-04-11 19:06:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-11 19:06:51 +0100 |
| commit | 76a8dd16e0bea51c6a3ec3e1bceabab7233ac092 (patch) | |
| tree | da5045b2ce8c5fb7f265a9e025f054c712ab4fb1 /challenge-160 | |
| parent | 0e26a7bedaebbaaa834c70749493c8f586f3516f (diff) | |
| parent | 672c5b1005558a2701ebde330fa6244503a534c5 (diff) | |
| download | perlweeklychallenge-club-76a8dd16e0bea51c6a3ec3e1bceabab7233ac092.tar.gz perlweeklychallenge-club-76a8dd16e0bea51c6a3ec3e1bceabab7233ac092.tar.bz2 perlweeklychallenge-club-76a8dd16e0bea51c6a3ec3e1bceabab7233ac092.zip | |
Merge pull request #5921 from k-mx/master
Challenge-160/1 by Maxim Kolodyazhny
Diffstat (limited to 'challenge-160')
| -rw-r--r-- | challenge-160/maxim-kolodyazhny/elixir/four_is_magic.ex | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-160/maxim-kolodyazhny/elixir/four_is_magic.ex b/challenge-160/maxim-kolodyazhny/elixir/four_is_magic.ex new file mode 100644 index 0000000000..17e5536f74 --- /dev/null +++ b/challenge-160/maxim-kolodyazhny/elixir/four_is_magic.ex @@ -0,0 +1,22 @@ +defmodule FourIsMagic do + def encode(n) when n in 1..9, do: encode(n, []) + defp encode(4, io), do: [io, "four is magic."] |> to_string |> String.capitalize() + + defp encode(n, io) do + names = %{ + 1 => "one", + 2 => "two", + 3 => "three", + 4 => "four", + 5 => "five", + 6 => "six", + 7 => "seven", + 8 => "eight", + 9 => "nine" + } + + name_len = (n_name = names[n]) |> String.length() + + encode(name_len, [io, n_name, " is #{names[name_len]}, "]) + end +end |
