···
|> String.split("\n", trim: true)
40
-
result = Regex.named_captures(~r/move (?<count>\d+) from (?<from>\d) to (?<to>\d)/, move)
43
-
count: String.to_integer(result["count"]),
44
-
from: String.to_integer(result["from"]),
45
-
to: String.to_integer(result["to"])
40
+
Regex.named_captures(~r/move (?<count>\d+) from (?<from>\d) to (?<to>\d)/, move)
41
+
|> Map.new(fn {k, v} -> {String.to_atom(k), String.to_integer(v)} end)
···
63
-
|> Enum.map(&Tuple.to_list/1)
64
-
|> Enum.map(fn column -> Enum.drop_while(column, &is_nil/1) end)
58
+
|> Enum.map(fn column -> column |> Tuple.to_list() |> Enum.drop_while(&is_nil/1) end)
|> Map.new(fn {v, k} -> {k, v} end)
···
Map.update!(columns, to, &(moved ++ &1))
89
+
def eval(crates, moves, reverse? \\ true) do
91
+
|> Enum.reduce(crates, &Day05.move(&1, &2, reverse?))
93
+
|> Enum.map(fn {_, v} -> hd(v) end)
<!-- livebook:{"output":true} -->
100
-
{:module, Day05, <<70, 79, 82, 49, 0, 0, 10, ...>>, {:move, 3}}
101
+
{:module, Day05, <<70, 79, 82, 49, 0, 0, 13, ...>>, {:eval, 3}}
107
-
|> Enum.reduce(crates, &Day05.move/2)
109
-
|> Enum.map(fn {_, v} -> hd(v) end)
107
+
Day05.eval(crates, moves)
<!-- livebook:{"output":true} -->
···
122
-
|> Enum.reduce(crates, &Day05.move(&1, &2, false))
124
-
|> Enum.map(fn {_, v} -> hd(v) end)
119
+
Day05.eval(crates, moves, false)
<!-- livebook:{"output":true} -->