diff options
-rw-r--r-- | 002.ex | 14 | ||||
-rw-r--r-- | 002.py | 8 |
2 files changed, 22 insertions, 0 deletions
@@ -0,0 +1,14 @@ +defmodule Fib do + def fib(1) do 1 end + def fib(2) do 2 end + def fib(n) do fib(n - 1) + fib(n - 2) end + + def solve(list, count) do + if (n = fib(count)) < 4000000 do + [if rem(n, 2) == 0 do n else 0 end | list] + |> solve(count + 1) + else list end + end +end + +IO.puts(Enum.sum(Fib.solve([0], 1))) @@ -0,0 +1,8 @@ +def fibo(max): + a, b = 1, 2 + while a < max: + yield a + a, b = b, a + b + + +print(sum(list(filter(lambda n: n % 2 == 0, list(fibo(4000000)))))) |