Skip to content

Instantly share code, notes, and snippets.

@tyamagu2
Last active August 29, 2015 14:22
Show Gist options
  • Save tyamagu2/bfd0c76bbd78c56c90da to your computer and use it in GitHub Desktop.
Save tyamagu2/bfd0c76bbd78c56c90da to your computer and use it in GitHub Desktop.
project_euler
# 1. Find the sum of all the multiples of 3 or 5 below 1000.
1..999 |> Enum.filter(&(rem(&1, 3) == 0 || rem(&1, 5) == 0)) |> Enum.reduce(&+/2)
# 2. By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Stream.unfold({1, 2}, fn {n1, n2} -> {n1, {n2, n1 + n2}} end) |> Stream.filter(&(rem(&1, 2) == 0)) |> Enum.take_while(&(&1 < 4000_000)) |> Enum.reduce(&+/2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment