From 9ff679d025151184818542a155065da5dbcbc5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Sat, 29 Jan 2022 19:17:17 +0100 Subject: 003: Add fully functional elixir solution --- 003.ex | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 003.ex 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 + -- cgit v1.2.3