Created
May 10, 2016 13:42
-
-
Save benthor/d75c67ddb3b059c94b11c5caca41a910 to your computer and use it in GitHub Desktop.
Brief test if I got the gist of elixir.
This file contains hidden or 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 Prime do | |
def checksieve([], _) do | |
true | |
end | |
def checksieve([head | tail], candidate) do | |
if rem(candidate, head) == 0 do | |
false | |
else | |
checksieve(tail, candidate) | |
end | |
end | |
def fill(list, candidate) do | |
if not checksieve(list, candidate) do | |
fill(list, candidate + 1) | |
else | |
IO.puts candidate | |
fill(list ++ [candidate], candidate + 2) | |
end | |
end | |
end | |
Prime.fill([2], 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment