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
1 changed files with 3 additions and 1 deletions

View File

@ -19,7 +19,9 @@ defmodule Day5 do
end
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
def input do