Created
November 3, 2015 09:01
-
-
Save maiah/5fc20f2e46c2a36f9438 to your computer and use it in GitHub Desktop.
Recursive solution to http://elixirexperience.com/problems/2
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 P2 do | |
def num_to_list(mx) when mx > 1 do | |
num_to_list(mx, mx - 1) | |
end | |
def num_to_list(mx) do | |
"#{mx}" | |
end | |
defp num_to_list(n, mx) when mx > 1 do | |
num_to_list("#{mx},#{n}", mx - 1) | |
end | |
defp num_to_list(n, mx) do | |
"#{mx},#{n}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment