r/adventofcode • u/daggerdragon • Dec 22 '20
SOLUTION MEGATHREAD -π- 2020 Day 22 Solutions -π-
Advent of Code 2020: Gettin' Crafty With It
- 23:59 hours remaining until the submission deadline TONIGHT at 23:59 EST!
- Full details and rules are in the Submissions Megathread
--- Day 22: Crab Combat ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:20:53, megathread unlocked!
35
Upvotes
View all comments
Show parent comment
1
u/Smylers Dec 23 '20
Full source
Added lines:
For anybody who doesn't read Perl:
0 .. $#handis the range of indices in the@handarray, each player's hand. We have 2 players, so it's just0, 1.max_bygives us the player index with the maximum by the criteria specified in the block, setting$_to each index in turn.$hand[$_]->@*is the list of cards for the player with index$_.maxdoes what you'd expect.maxfinds the maximum card in their hand, thenmax_byreturns the index of the player with the maximum maximum.PlayerΒ 1 has indexΒ 0, so return
0as the winner when that player has the max card.It definitely is doing some shortcutting (and still getting the same answer, with playerΒ 2 eventually winning) β just not much.