Skip to content

Instantly share code, notes, and snippets.

@testfirstcoder
Last active November 12, 2015 14:26
Show Gist options
  • Save testfirstcoder/9c17a8676ed212328400 to your computer and use it in GitHub Desktop.
Save testfirstcoder/9c17a8676ed212328400 to your computer and use it in GitHub Desktop.
ProjectEuler in Elixir
1..1000 - 1 |> Enum.filter(fn x -> (rem x, 3) == 0 || (rem x, 5) == 0 end) |> Enum.sum
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
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)
(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)
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