annotate day8.txt @ 29:739415015d27

Implement Day 20 switches part 1
author IBBoard <dev@ibboard.co.uk>
date Wed, 03 Jan 2024 11:35:22 +0000
parents 1e16a25a9553
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 --- Day 8: Haunted Wasteland ---
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
3 You have a map that describes a list of nodes. It seems like you're meant to use the left/right instructions to navigate the network.
11
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
5 AAA is where you are now, and you have to follow the left/right instructions until you reach ZZZ.
11
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 This format defines each node of the network individually. For example:
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 RL
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 AAA = (BBB, CCC)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 BBB = (DDD, EEE)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 CCC = (ZZZ, GGG)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 DDD = (DDD, DDD)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 EEE = (EEE, EEE)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 GGG = (GGG, GGG)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 ZZZ = (ZZZ, ZZZ)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 Starting with AAA, you need to look up the next element based on the next left/right instruction in your input. In this example, start with AAA and go right (R) by choosing the right element of AAA, CCC. Then, L means to choose the left element of CCC, ZZZ. By following the left/right instructions, you reach ZZZ in 2 steps.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 Of course, you might not find ZZZ right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: RL really means RLRLRLRLRLRLRLRL... and so on. For example, here is a situation that takes 6 steps to reach ZZZ:
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 LLR
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 AAA = (BBB, BBB)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 BBB = (AAA, ZZZ)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 ZZZ = (ZZZ, ZZZ)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 Starting at AAA, follow the left/right instructions. How many steps are required to reach ZZZ?
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 --- Part Two ---
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
19
1e16a25a9553 Strip down the text to just the puzzle, not the fluff
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
33 The number of nodes with names ending in A is equal to the number ending in Z! You actually have to start at every node that ends with A and follow all of the paths at the same time until they all simultaneously end up at nodes that end with Z.
11
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 For example:
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 LR
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 11A = (11B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 11B = (XXX, 11Z)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 11Z = (11B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 22A = (22B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 22B = (22C, 22C)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 22C = (22Z, 22Z)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 22Z = (22B, 22B)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 XXX = (XXX, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Here, there are two starting nodes, 11A and 22A (because they both end with A). As you follow each left/right instruction, use that instruction to simultaneously navigate away from both nodes you're currently on. Repeat this process until all of the nodes you're currently on end with Z. (If only some of the nodes you're on end with Z, they act like any other node and you continue as normal.) In this example, you would proceed as follows:
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Step 0: You are at 11A and 22A.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Step 1: You choose all of the left paths, leading you to 11B and 22B.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 Step 2: You choose all of the right paths, leading you to 11Z and 22C.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 Step 3: You choose all of the left paths, leading you to 11B and 22Z.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 Step 4: You choose all of the right paths, leading you to 11Z and 22B.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 Step 5: You choose all of the left paths, leading you to 11B and 22C.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 Step 6: You choose all of the right paths, leading you to 11Z and 22Z.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 So, in this example, you end up entirely on nodes that end in Z after 6 steps.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 Simultaneously start on every node that ends with A. How many steps does it take before you're only on nodes that end with Z?