aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2022-01-29 19:17:17 +0100
committerRomain Gonçalves <me@rgoncalves.se>2022-01-29 19:20:50 +0100
commit9ff679d025151184818542a155065da5dbcbc5a1 (patch)
tree7c5fd2390b4425d544d154a80dcea381f353370d
parent24b3966960a65775bfffca514600e2e47304d000 (diff)
downloadprojecteuler-9ff679d025151184818542a155065da5dbcbc5a1.tar.gz
003: Add fully functional elixir solution
-rw-r--r--003.ex9
1 files changed, 9 insertions, 0 deletions
diff --git a/003.ex b/003.ex
new file mode 100644
index 0000000..83bc349
--- /dev/null
+++ b/003.ex
@@ -0,0 +1,9 @@
+n = 600851475143
+
+(for x <- 2..trunc(:math.sqrt(n / 2)), rem(n, x) == 0, do: x)
+|> Enum.reduce_while(n, fn x, acc ->
+ if acc == x, do: {:halt, x}, else: {:cont, acc / x}
+ end)
+|> trunc
+|> IO.puts
+
remember that computers suck.