Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0be2dad

Browse files
committed
solution day 8
1 parent f8969ad commit 0be2dad

File tree

6 files changed

+1032
-0
lines changed

6 files changed

+1032
-0
lines changed

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ add_subdirectory ("day04")
1313
add_subdirectory ("day05")
1414
add_subdirectory ("day06")
1515
add_subdirectory ("day07")
16+
add_subdirectory ("day08")

‎day08/CMakeLists.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required (VERSION 3.27)
2+
3+
get_filename_component (CURRENT_DAY ${CMAKE_CURRENT_SOURCE_DIR} NAME)
4+
5+
configure_file("input.txt" "input.txt" COPYONLY)
6+
7+
add_executable (${CURRENT_DAY}part1 "part1.cpp" )
8+
add_executable (${CURRENT_DAY}part2 "part2.cpp" )
9+
10+
set_property(TARGET ${CURRENT_DAY}part1 PROPERTY CXX_STANDARD 23)
11+
set_property(TARGET ${CURRENT_DAY}part1 PROPERTY CMAKE_CXX_STANDARD_REQUIRED YES)
12+
set_property(TARGET ${CURRENT_DAY}part2 PROPERTY CXX_STANDARD 23)
13+
set_property(TARGET ${CURRENT_DAY}part2 PROPERTY CMAKE_CXX_STANDARD_REQUIRED YES)

‎day08/README.md‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Day 8: Haunted Wasteland
2+
3+
[https://adventofcode.com/2023/day/8](https://adventofcode.com/2023/day/8)
4+
5+
## Description
6+
7+
### Part One
8+
9+
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.
10+
11+
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.
12+
13+
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!
14+
15+
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`.
16+
17+
This format defines each _node_ of the network individually. For example:
18+
19+
RL
20+
21+
AAA = (BBB, CCC)
22+
BBB = (DDD, EEE)
23+
CCC = (ZZZ, GGG)
24+
DDD = (DDD, DDD)
25+
EEE = (EEE, EEE)
26+
GGG = (GGG, GGG)
27+
ZZZ = (ZZZ, ZZZ)
28+
29+
30+
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.
31+
32+
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`:
33+
34+
LLR
35+
36+
AAA = (BBB, BBB)
37+
BBB = (AAA, ZZZ)
38+
ZZZ = (ZZZ, ZZZ)
39+
40+
41+
Starting at `AAA`, follow the left/right instructions. _How many steps are required to reach `ZZZ`?_
42+
43+
### Part Two
44+
45+
The <span title="Duhduhduhduhduh! Dah, duhduhduhduhduh!">sandstorm</span> 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!
46+
47+
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.
48+
49+
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`.
50+
51+
For example:
52+
53+
LR
54+
55+
11A = (11B, XXX)
56+
11B = (XXX, 11Z)
57+
11Z = (11B, XXX)
58+
22A = (22B, XXX)
59+
22B = (22C, 22C)
60+
22C = (22Z, 22Z)
61+
22Z = (22B, 22B)
62+
XXX = (XXX, XXX)
63+
64+
65+
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:
66+
67+
* Step 0: You are at `11A` and `22A`.
68+
* Step 1: You choose all of the _left_ paths, leading you to `11B` and `22B`.
69+
* Step 2: You choose all of the _right_ paths, leading you to _`11Z`_ and `22C`.
70+
* Step 3: You choose all of the _left_ paths, leading you to `11B` and _`22Z`_.
71+
* Step 4: You choose all of the _right_ paths, leading you to _`11Z`_ and `22B`.
72+
* Step 5: You choose all of the _left_ paths, leading you to `11B` and `22C`.
73+
* Step 6: You choose all of the _right_ paths, leading you to _`11Z`_ and _`22Z`_.
74+
75+
So, in this example, you end up entirely on nodes that end in `Z` after _`6`_ steps.
76+
77+
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`?_

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /