This commit is contained in:
bluepython508
2023-12-13 12:17:31 +00:00
parent 131f501b91
commit 03b92dd930
6 changed files with 67 additions and 1 deletions

View File

@@ -37,7 +37,9 @@ defmodule Aoc2023.Common do
def lines(x), do: String.split(x, "\n")
def head([head | _]), do: head
def head([]), do: nil
def tail([_ | tail]), do: tail
def tail([]), do: nil
def lcm(a, b), do: div(abs(a*b), Integer.gcd(a,b))
def lcm(ls), do: ls |> Enum.reduce(&lcm/2)
@@ -55,6 +57,6 @@ defmodule Aoc2023.Common do
|> Stream.map(pipe(elem(0)))
end
def repeat(lst, 0), do: []
def repeat(_, 0), do: []
def repeat(lst, n), do: Enum.concat(lst, repeat(lst, n - 1))
end