fix top_crates function that assumed ordered map

This commit is contained in:
Adam Millerchip 2022-12-06 10:52:26 +09:00
parent a6911216fa
commit 58df8b822b

View file

@ -19,7 +19,9 @@ defmodule Day5 do
end end
defp top_crates(stacks) do defp top_crates(stacks) do
Enum.reduce(stacks, "", fn {_label, [top | _stack]}, acc -> acc <> top end) stacks
|> Enum.sort_by(fn {label, _stack} -> label end)
|> Enum.reduce("", fn {_label, [top | _stack]}, acc -> acc <> top end)
end end
def input do def input do