VP 33: Mixing Cups (15 pts + 20 extra)

What You Need

Any computer with Python 3. You can also use an online Python environment, such as https://colab.research.google.com

Mixing Cups Game

We'll call your opponent Sally.

In this game, Sally is going to mix up some cups, and you have to predict where they'll end up.

The cups will be arranged in a circle and labeled clockwise (your puzzle input). For example, if your labeling were 32415, there would be five cups in the circle; going clockwise around the circle from the first cup, the cups would be labeled 3, 2, 4, 1, 5, and then back to 3 again.

Before Sally starts, she will designate the first cup in your list as the current cup. She will then do 100 moves.

Each move consists of the following actions:

Sally picks up the three cups that are immediately clockwise of the current cup. They are removed from the circle; cup spacing is adjusted as necessary to maintain the circle.

Sally selects a destination cup: the cup with a label equal to the current cup's label minus one. If this would select one of the cups that was just picked up, she will keep subtracting one until she finds a cup that wasn't just picked up. If at any point in this process the value goes below the lowest value on any cup's label, it wraps around to the highest value on any cup's label instead.

Sally places the cups she just picked up so that they are immediately clockwise of the destination cup. They keep the same order as when they were picked up.

Sally selects a new current cup: the cup which is immediately clockwise of the current cup.

For example, suppose your cup labeling were 389125467. If Sally were to do merely 10 moves, the following changes would occur:

-- move 1 --
cups: (3) 8  9  1  2  5  4  6  7 
pick up: 8, 9, 1
destination: 2

-- move 2 --
cups:  3 (2) 8  9  1  5  4  6  7 
pick up: 8, 9, 1
destination: 7

-- move 3 --
cups:  3  2 (5) 4  6  7  8  9  1 
pick up: 4, 6, 7
destination: 3

-- move 4 --
cups:  7  2  5 (8) 9  1  3  4  6 
pick up: 9, 1, 3
destination: 7

-- move 5 --
cups:  3  2  5  8 (4) 6  7  9  1 
pick up: 6, 7, 9
destination: 3

-- move 6 --
cups:  9  2  5  8  4 (1) 3  6  7 
pick up: 3, 6, 7
destination: 9

-- move 7 --
cups:  7  2  5  8  4  1 (9) 3  6 
pick up: 3, 6, 7
destination: 8

-- move 8 --
cups:  8  3  6  7  4  1  9 (2) 5 
pick up: 5, 8, 3
destination: 1

-- move 9 --
cups:  7  4  1  5  8  3  9  2 (6)
pick up: 7, 4, 1
destination: 5

-- move 10 --
cups: (5) 7  4  1  8  3  9  2  6 
pick up: 7, 4, 1
destination: 3

-- final --
cups:  5 (8) 3  7  4  1  9  2  6 
In the above example, the cups' values are the labels as they appear moving clockwise around the circle; the current cup is marked with ( ).

After Sally is done, what order will the cups be in? Starting after the cup labeled 1, collect the other cups' labels clockwise into a single string with no extra characters; each number except 1 should appear exactly once. In the above example, after 10 moves, the cups clockwise from 1 are labeled 9, 2, 6, 5, and so on, producing 92658374. If Sally were to complete all 100 moves, the order after cup 1 would be 67384529.

Using your labeling, simulate 100 moves.

VP 33.1: Mixing Cups (15 pts)

Your puzzle input is 368195742.

Perform 100 moves, as explained above.

What are the labels on the cups after cup 1? Concatenate them into a single eight-digit number.

That number is the flag.

One Thousand Cups

Now extend the game to a larger set of cups.

Your labeling is still correct for the first few cups; after that, the remaining cups are just numbered in an increasing fashion starting from the number after the highest number in your list and proceeding one by one until one thousand is reached. (For example, if your labeling were 54321, the cups would be numbered 5, 4, 3, 2, 1, and then start counting up from 6 until one million is reached.) In this way, every number from one through one million is used exactly once.

Now, Sally isn't going to do merely 100 moves; she will do ten thousand (10000) moves!

To find the flag, find the two cups that will end up immediately clockwise of the current cup after the final move, and multiply their labels together.

In the above example (389125467), the result is:

cups: (310) 804 659 
cup_length, Elapsed time: 1000 2.03
So the flag would be 804 * 659 = 529836.

VP 33.2: One Thousand Cups (10 pts extra)

Your puzzle input is 368195742.

Extend the list to 1000 cups, as explained above

Perform 10,000 moves, as explained above.

Find the two cups after the current cup, and multiply their labels together.

That number is the flag.

Ten Thousand Cups

Now extend the game to 10,000 cups, as explained above

Perform 100,000 moves, as explained above.

In the above example (389125467), the result is:

cups: (705) 2452 9056 flag: 22205312
cup_length, Elapsed time: 10000 241.71
Notice that the time is increasing as O(n^2). My code is very inefficient. It could be improved a lot.

VP 33.3: Ten Thousand Cups (10 pts extra)

Your puzzle input is 368195742.

Extend the list to 10,000 cups, as explained above

Perform 100,000 moves, as explained above.

Find the two cups after the current cup, and multiply their labels together.

That number is the flag.

Source

Adapted from the Advent of Code.

Posted 10-15-24