Created
November 1, 2016 08:04
-
-
Save MaroShim/f227a9f1081a5bb8a8ba278690f18305 to your computer and use it in GitHub Desktop.
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
# largest factor of 600851475143 | |
defmodule Problem3 do | |
# http://wende.github.io/2015/09/07/Elixir-n-prime-numbers.html | |
def prime?(x), do: (2..round(:math.sqrt(x)) |> Enum.filter(fn a -> rem(x, a) == 0 end) |> length()) == 0 | |
def solve(num) do | |
(2 .. round(:math.sqrt(num))) | |
|> Stream.filter(&(rem(num, &1) == 0)) | |
|> Stream.filter(&(prime?(&1))) | |
|> Enum.to_list | |
end | |
def print do | |
IO.inspect solve(600851475143) | |
end | |
end | |
Problem3.print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment