aboutsummaryrefslogtreecommitdiffstats
path: root/002.ex
diff options
context:
space:
mode:
Diffstat (limited to '002.ex')
-rw-r--r--002.ex14
1 files changed, 14 insertions, 0 deletions
diff --git a/002.ex b/002.ex
new file mode 100644
index 0000000..f58cc4c
--- /dev/null
+++ b/002.ex
@@ -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)))
remember that computers suck.