Skip to content

Instantly share code, notes, and snippets.

@benthor
Created May 10, 2016 13:42
Show Gist options
  • Save benthor/d75c67ddb3b059c94b11c5caca41a910 to your computer and use it in GitHub Desktop.
Save benthor/d75c67ddb3b059c94b11c5caca41a910 to your computer and use it in GitHub Desktop.
Brief test if I got the gist of elixir.
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