part1 (3357B)
1--- Day 23: Crab Cups --- 2 3The small crab challenges [1m[37myou[0m to a game! The crab is going to mix up some cups, and you 4have to predict where they'll end up. 5 6The cups will be arranged in a circle and labeled [1m[37mclockwise[0m (your puzzle input). For 7example, if your labeling were 32415, there would be five cups in the circle; going clockwise around 8the circle from the first cup, the cups would be labeled 3, 2, 4, 1, 5, and then back to 3 again. 9 10Before the crab starts, it will designate the first cup in your list as the [1m[37mcurrent 11cup[0m. The crab is then going to do [1m[37m100 moves[0m. 12 13Each [1m[37mmove[0m, the crab does the following actions: 14 15 16 - The crab picks up the [1m[37mthree cups[0m that are immediately [1m[37mclockwise[0m of the 17[1m[37mcurrent cup[0m. They are removed from the circle; cup spacing is adjusted as necessary to 18maintain the circle. 19 - The crab selects a [1m[37mdestination cup[0m: the cup with a [1m[37mlabel[0m equal to the 20[1m[37mcurrent cup's[0m label minus one. If this would select one of the cups that was just 21picked up, the crab will keep subtracting one until it finds a cup that wasn't just picked up. If at 22any point in this process the value goes below the lowest value on any cup's label, it 23[1m[37mwraps around[0m to the highest value on any cup's label instead. 24 - The crab places the cups it just picked up so that they are [1m[37mimmediately clockwise[0m of 25the destination cup. They keep the same order as when they were picked up. 26 - The crab selects a new [1m[37mcurrent cup[0m: the cup which is immediately clockwise of the 27current cup. 28 29 30For example, suppose your cup labeling were 389125467. If the crab were to do merely 10 moves, the 31following changes would occur: 32 33-- move 1 -- 34cups: (3) 8 9 1 2 5 4 6 7 35pick up: 8, 9, 1 36destination: 2 37 38-- move 2 -- 39cups: 3 (2) 8 9 1 5 4 6 7 40pick up: 8, 9, 1 41destination: 7 42 43-- move 3 -- 44cups: 3 2 (5) 4 6 7 8 9 1 45pick up: 4, 6, 7 46destination: 3 47 48-- move 4 -- 49cups: 7 2 5 (8) 9 1 3 4 6 50pick up: 9, 1, 3 51destination: 7 52 53-- move 5 -- 54cups: 3 2 5 8 (4) 6 7 9 1 55pick up: 6, 7, 9 56destination: 3 57 58-- move 6 -- 59cups: 9 2 5 8 4 (1) 3 6 7 60pick up: 3, 6, 7 61destination: 9 62 63-- move 7 -- 64cups: 7 2 5 8 4 1 (9) 3 6 65pick up: 3, 6, 7 66destination: 8 67 68-- move 8 -- 69cups: 8 3 6 7 4 1 9 (2) 5 70pick up: 5, 8, 3 71destination: 1 72 73-- move 9 -- 74cups: 7 4 1 5 8 3 9 2 (6) 75pick up: 7, 4, 1 76destination: 5 77 78-- move 10 -- 79cups: (5) 7 4 1 8 3 9 2 6 80pick up: 7, 4, 1 81destination: 3 82 83-- final -- 84cups: 5 (8) 3 7 4 1 9 2 6 85 86In the above example, the cups' values are the labels as they appear moving clockwise around the 87circle; the [1m[37mcurrent cup[0m is marked with ( ). 88 89After the crab is done, what order will the cups be in? Starting [1m[37mafter the cup labeled 901[0m, collect the other cups' labels clockwise into a single string with no extra characters; each 91number except 1 should appear exactly once. In the above example, after 10 moves, the cups clockwise 92from 1 are labeled 9, 2, 6, 5, and so on, producing [1m[37m92658374[0m. If the crab were to 93complete all 100 moves, the order after cup 1 would be [1m[37m67384529[0m. 94 95Using your labeling, simulate 100 moves. [1m[37mWhat are the labels on the cups after cup 1?[0m 96 97