Skip to content

Instantly share code, notes, and snippets.

View MaroShim's full-sized avatar

Maro Shim MaroShim

  • NCSOFT
  • 18:13 (UTC +09:00)
View GitHub Profile
# 3digit * 3digit, which is palindrome
defmodule Problem4 do
def palindrome?(n) do
s = to_string(n)
String.reverse(s) == s
end
def solve do
# largest factor of 600851475143
defmodule Problem3 do
# http://wende.github.io/2015/09/07/Elixir-n-prime-numbers.html
def prime?(x), do: (2..round(:math.sqrt(x)) |> Enum.filter(fn a -> rem(x, a) == 0 end) |> length()) == 0
def solve(num) do
(2 .. round(:math.sqrt(num)))
# sum of fibonacci numbers which is even and less than 4000000
# https://elixirforum.com/t/project-euler-problem-2/500/2
defmodule Problem2 do
def fib_seq do
Stream.unfold({1,1}, fn {a,b} -> {a, {b, a + b}} end)
end
# less than 1000, multiple of 3 or 5
defmodule Problem1 do
def solve(limit) do
1..(limit-1)
|> Enum.filter(fn x -> ((rem(x, 3) == 0) || (rem(x, 5) == 0)) end)
|> Enum.reduce(0, &(&1 + &2))
end