This commit is contained in:
bluepython508
2023-12-12 11:26:48 +00:00
parent e9367fd784
commit 131f501b91
6 changed files with 112 additions and 0 deletions

View File

@@ -47,4 +47,14 @@ defmodule Aoc2023.Common do
end
def transpose(l), do: l |> Enum.zip |> Enum.map(&Tuple.to_list/1)
def collapse(enum, v) do
enum
|> Stream.zip(enum |> Stream.drop(1) |> Stream.concat([nil]))
|> Stream.filter(fn {a, b} -> a != v || b != v end)
|> Stream.map(pipe(elem(0)))
end
def repeat(lst, 0), do: []
def repeat(lst, n), do: Enum.concat(lst, repeat(lst, n - 1))
end