annotate day8.txt @ 12:891878e52a31

Implement Day 9 - diffing and predicting There might be a better way with Reduce instead of pushing values into the arrays, but it's quick and it worked
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Dec 2023 16:55:59 +0000
parents a7fb64b48830
children 1e16a25a9553
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
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 You're still riding a camel across Desert Island when you spot a sandstorm quickly approaching. When you turn to warn the Elf, she disappears before your eyes! To be fair, she had just finished warning you about ghosts a few minutes ago.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 One of the camel's pouches is labeled "maps" - sure enough, it's full of documents (your puzzle input) about how to navigate the desert. At least, you're pretty sure that's what they are; one of the documents contains a list of left/right instructions, and the rest of the documents seem to describe some kind of network of labeled nodes.
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 It seems like you're meant to use the left/right instructions to navigate the network. Perhaps if you have the camel follow the same instructions, you can escape the haunted wasteland!
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 After examining the maps for a bit, two nodes stick out: AAA and ZZZ. You feel like AAA is where you are now, and you have to follow the left/right instructions until you reach ZZZ.
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 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
12
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 RL
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 AAA = (BBB, CCC)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 BBB = (DDD, EEE)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 CCC = (ZZZ, GGG)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 DDD = (DDD, DDD)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 EEE = (EEE, EEE)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 GGG = (GGG, GGG)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 ZZZ = (ZZZ, 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 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
24
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 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
26
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 LLR
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 AAA = (BBB, BBB)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 BBB = (AAA, ZZZ)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 ZZZ = (ZZZ, ZZZ)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 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
34
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 --- Part Two ---
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 The sandstorm is upon you and you aren't any closer to escaping the wasteland. You had the camel follow the instructions, but you've barely left your starting position. It's going to take significantly more steps to escape!
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 What if the map isn't for people - what if the map is for ghosts? Are ghosts even bound by the laws of spacetime? Only one way to find out.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 After examining the maps a bit longer, your attention is drawn to a curious fact: the number of nodes with names ending in A is equal to the number ending in Z! If you were a ghost, you'd probably just 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.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 For example:
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 LR
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 11A = (11B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 11B = (XXX, 11Z)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 11Z = (11B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 22A = (22B, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 22B = (22C, 22C)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 22C = (22Z, 22Z)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 22Z = (22B, 22B)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 XXX = (XXX, XXX)
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 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
57
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 Step 0: You are at 11A and 22A.
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 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
60 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
61 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
62 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
63 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
64 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
65
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 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
67
a7fb64b48830 Implement Day 8 - node/map walking
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 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?