part1 (3282B)
1--- Day 22: Crab Combat --- 2 3It only takes a few hours of sailing the ocean on a raft for boredom to sink in. Fortunately, you 4brought a small deck of space cards! You'd like to play a game of [1m[37mCombat[0m, and there's 5even an opponent available: a small crab that climbed aboard your raft before you left. 6 7Fortunately, it doesn't take long to teach the crab the rules. 8 9Before the game starts, split the cards so each player has their own deck (your puzzle input). Then, 10the game consists of a series of [1m[37mrounds[0m: both players draw their top card, and the 11player with the higher-valued card wins the round. The winner keeps both cards, placing them on the 12bottom of their own deck so that the winner's card is above the other card. If this causes a player 13to have all of the cards, they win, and the game ends. 14 15For example, consider the following starting decks: 16 17Player 1: 189 192 206 213 221 23 24Player 2: 255 268 274 287 2910 30 31This arrangement means that player 1's deck contains 5 cards, with 9 on top and 1 on the bottom; 32player 2's deck also contains 5 cards, with 5 on top and 10 on the bottom. 33 34The first round begins with both players drawing the top card of their decks: 9 and 5. Player 1 has 35the higher card, so both cards move to the bottom of player 1's deck such that 9 is above 5. In 36total, it takes 29 rounds before a player has all of the cards: 37 38-- Round 1 -- 39Player 1's deck: 9, 2, 6, 3, 1 40Player 2's deck: 5, 8, 4, 7, 10 41Player 1 plays: 9 42Player 2 plays: 5 43Player 1 wins the round! 44 45-- Round 2 -- 46Player 1's deck: 2, 6, 3, 1, 9, 5 47Player 2's deck: 8, 4, 7, 10 48Player 1 plays: 2 49Player 2 plays: 8 50Player 2 wins the round! 51 52-- Round 3 -- 53Player 1's deck: 6, 3, 1, 9, 5 54Player 2's deck: 4, 7, 10, 8, 2 55Player 1 plays: 6 56Player 2 plays: 4 57Player 1 wins the round! 58 59-- Round 4 -- 60Player 1's deck: 3, 1, 9, 5, 6, 4 61Player 2's deck: 7, 10, 8, 2 62Player 1 plays: 3 63Player 2 plays: 7 64Player 2 wins the round! 65 66-- Round 5 -- 67Player 1's deck: 1, 9, 5, 6, 4 68Player 2's deck: 10, 8, 2, 7, 3 69Player 1 plays: 1 70Player 2 plays: 10 71Player 2 wins the round! 72 73...several more rounds pass... 74 75-- Round 27 -- 76Player 1's deck: 5, 4, 1 77Player 2's deck: 8, 9, 7, 3, 2, 10, 6 78Player 1 plays: 5 79Player 2 plays: 8 80Player 2 wins the round! 81 82-- Round 28 -- 83Player 1's deck: 4, 1 84Player 2's deck: 9, 7, 3, 2, 10, 6, 8, 5 85Player 1 plays: 4 86Player 2 plays: 9 87Player 2 wins the round! 88 89-- Round 29 -- 90Player 1's deck: 1 91Player 2's deck: 7, 3, 2, 10, 6, 8, 5, 9, 4 92Player 1 plays: 1 93Player 2 plays: 7 94Player 2 wins the round! 95 96 97== Post-game results == 98Player 1's deck: 99Player 2's deck: 3, 2, 10, 6, 8, 5, 9, 4, 7, 1 100 101Once the game ends, you can calculate the winning player's [1m[37mscore[0m. The bottom card in 102their deck is worth the value of the card multiplied by 1, the second-from-the-bottom card is worth 103the value of the card multiplied by 2, and so on. With 10 cards, the top card is worth the value on 104the card multiplied by 10. In this example, the winning player's score is: 105 106 3 * 10 107+ 2 * 9 108+ 10 * 8 109+ 6 * 7 110+ 8 * 6 111+ 5 * 5 112+ 9 * 4 113+ 4 * 3 114+ 7 * 2 115+ 1 * 1 116= 306 117 118So, once the game ends, the winning player's score is [1m[37m306[0m. 119 120Play the small crab in a game of Combat using the two decks you just dealt. [1m[37mWhat is the 121winning player's score?[0m 122 123