1
0
Fork 0

simplify compare_hands

This commit is contained in:
sloane 2023-12-07 10:59:45 -05:00
parent dcbdbcf128
commit dfda215b9d
No known key found for this signature in database

View file

@ -21,7 +21,7 @@ aoc 2023, 7 do
[counts, hand, bet] [counts, hand, bet]
end) end)
|> Enum.sort(&compare_hands_1/2) |> Enum.sort(&compare_hands/2)
|> Enum.map(&Enum.at(&1, 2)) |> Enum.map(&Enum.at(&1, 2))
|> Enum.with_index(1) |> Enum.with_index(1)
|> Enum.map(fn {bet, rank} -> bet * rank end) |> Enum.map(fn {bet, rank} -> bet * rank end)
@ -56,7 +56,7 @@ aoc 2023, 7 do
[counts, hand, bet] [counts, hand, bet]
end) end)
|> Enum.sort(&compare_hands_1/2) |> Enum.sort(&compare_hands/2)
|> Enum.map(&Enum.at(&1, 2)) |> Enum.map(&Enum.at(&1, 2))
|> Enum.with_index(1) |> Enum.with_index(1)
|> Enum.map(fn {bet, rank} -> bet * rank end) |> Enum.map(fn {bet, rank} -> bet * rank end)
@ -79,6 +79,7 @@ aoc 2023, 7 do
|> Enum.map(card_to_number) |> Enum.map(card_to_number)
end end
def compare_hands_1([counts, hand_a, _], [counts, hand_b, _]), do: hand_a <= hand_b def compare_hands([counts_a, hand_a, _], [counts_b, hand_b, _]) do
def compare_hands_1([counts_a, _, _], [counts_b, _, _]), do: counts_a <= counts_b [counts_a, hand_a] <= [counts_b, hand_b]
end
end end