aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2022-01-28 18:51:40 +0100
committerRomain Gonçalves <me@rgoncalves.se>2022-01-28 18:51:40 +0100
commit24b3966960a65775bfffca514600e2e47304d000 (patch)
tree332e19d923e1bf930c5370e97e84d9ab74f9e438
parent7f93a4f807499441826042f59f9d5dad59854e69 (diff)
downloadprojecteuler-24b3966960a65775bfffca514600e2e47304d000.tar.gz
002: Add python and elixir solutions
-rw-r--r--002.ex14
-rw-r--r--002.py8
2 files changed, 22 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)))
diff --git a/002.py b/002.py
new file mode 100644
index 0000000..4edd181
--- /dev/null
+++ b/002.py
@@ -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))))))
remember that computers suck.