Last active
November 12, 2015 14:26
-
-
Save testfirstcoder/9c17a8676ed212328400 to your computer and use it in GitHub Desktop.
ProjectEuler in 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
1..1000 - 1 |> Enum.filter(fn x -> (rem x, 3) == 0 || (rem x, 5) == 0 end) |> Enum.sum |
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
Stream.unfold({1,2}, fn {a,b} -> {a, {b, a + b}} end) | |
|> Stream.take_while(&(&1 < 4000000)) | |
|> Stream.filter(fn e -> rem(e, 2) == 0 end) | |
|> Enum.sum |
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
Stream.unfold({1, 1, 1}, fn{i, a, b} -> {{i, a}, {i + 1, b, a + b}} end) | |
|> Enum.find(fn{_, e} -> (to_string(e)|> String.length()) == 1000 end) | |
|> elem(0) |
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
(for i <- 999..1, j <- i..1, do: i * j) | |
|> Enum.uniq | |
|> (Enum.sort &(&1 > &2)) | |
|> Enum.find(fn e -> e = to_string(e); e == String.reverse(e) end) |
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
range = 1..100; (s = range |> Enum.sum; s * s) - (range |> Enum.map(&(&1*&1)) |> Enum.sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment