Last active
October 12, 2022 20:16
-
-
Save dams/db9b37ccfe587ac1b54fc1b62db6adbd 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
defmodule Test do | |
def question_1(), do: question_1(100_000_000) | |
def question_1(num), do: question_1(num, rem(num, 1119)) | |
def question_1(num, 0), do: num | |
def question_1(num, _), do: question_1(num+1) | |
def question_2(num) do | |
num | |
|> Integer.to_string() | |
|> String.split("", trim: true) | |
end | |
def question_3(charlist), do: question_3(charlist, %{}) | |
def question_3([], res), do: res | |
def question_3([char|tail], res), do: question_3(tail, Map.update(res, char, 1, & &1+1)) | |
end | |
answer_1 = Test.question_1() | |
IO.puts(answer_1) | |
answer_2 = Test.question_2(answer_1) | |
IO.inspect(answer_2) | |
answer_3 = Test.question_3(answer_2) | |
IO.inspect(answer_3) | |
### Result on console: | |
# 100000554 | |
# ["1", "0", "0", "0", "0", "0", "5", "5", "4"] | |
# %{"0" => 5, "1" => 1, "4" => 1, "5" => 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment