Skip to content

Commit f3c7daa

Browse files
committed
2024-08
1 parent 394ba5e commit f3c7daa

File tree

11 files changed

+410
-25
lines changed

11 files changed

+410
-25
lines changed

2024/Cargo.lock

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2024/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ itertools = "0.12.0"
1111
pathfinding = "4.6.0"
1212
petgraph = "0.6.4"
1313
petgraph-evcxr = "0.2.0"
14+
rayon = "1.10.0"
1415
regex = "1.10.2"
1516
z3 = "0.12.1"

2024/src/day_04/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ enum Direction {
1414
fn rek(
1515
matrix: &Vec<Vec<u8>>,
1616
dir: Direction,
17-
pos: (isize, isize),
18-
bounds: (isize, isize),
17+
pos: (i32, i32),
18+
bounds: (i32, i32),
1919
off: usize,
2020
) -> u64 {
2121
if off == 4 {
@@ -50,7 +50,7 @@ fn rek(
5050
0
5151
}
5252

53-
fn check_pos(matrix: &[Vec<u8>], pos: (isize, isize), bounds: (isize, isize), char: u8) -> bool {
53+
fn check_pos(matrix: &[Vec<u8>], pos: (i32, i32), bounds: (i32, i32), char: u8) -> bool {
5454
if pos.0 < 0 || pos.1 < 0 {
5555
// we went OOB
5656
return false;
@@ -69,7 +69,7 @@ const M: u8 = 0x4d;
6969
const A: u8 = 0x41;
7070
const S: u8 = 0x53;
7171

72-
fn part_two(matrix: &[Vec<u8>], pos: (isize, isize), bounds: (isize, isize)) -> u64 {
72+
fn part_two(matrix: &[Vec<u8>], pos: (i32, i32), bounds: (i32, i32)) -> u64 {
7373
// S S
7474
// A
7575
// M M
@@ -118,8 +118,7 @@ fn part_two(matrix: &[Vec<u8>], pos: (isize, isize), bounds: (isize, isize)) ->
118118
}
119119

120120
pub fn solve(input: String) -> Vec<u64> {
121-
let matrix = aoc::parse_matrix(input);
122-
let bounds = (matrix[0].len() as isize - 1, matrix.len() as isize - 1);
121+
let (matrix, bounds) = aoc::parse_matrix(input);
123122

124123
let mut count = 0;
125124
let mut count2 = 0;

2024/src/day_06/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ fn find_start(matrix: &[Vec<u8>], bounds: &(i32, i32)) -> Step {
9494
}
9595

9696
pub fn solve(input: String) -> Vec<u64> {
97-
let matrix = aoc::parse_matrix(input);
98-
let bounds: (i32, i32) = (matrix[0].len() as i32 - 1, matrix.len() as i32 - 1);
97+
let (matrix, bounds) = aoc::parse_matrix(input);
9998

10099
let mut distinct_fields = HashSet::new();
101100

@@ -115,16 +114,7 @@ pub fn solve(input: String) -> Vec<u64> {
115114
.par_iter()
116115
// Skip the start point
117116
.filter(|(x, y)| start.x != *x || start.y != *y)
118-
.map(|(x, y)| {
119-
next(
120-
&matrix,
121-
start.clone(),
122-
&bounds,
123-
&mut None,
124-
(*x, *y),
125-
cap,
126-
)
127-
})
117+
.map(|(x, y)| next(&matrix, start.clone(), &bounds, &mut None, (*x, *y), cap))
128118
.sum();
129119

130120
vec![distinct_fields.len() as u64, loop_cnt]

2024/src/day_07/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ fn rek2(target: u64, status: u64, remaining_items: Vec<u64>) -> bool {
3535
remaining_items[1..].to_vec(),
3636
) || rek2(
3737
target,
38-
format!("{}{}", status, remaining_items[0])
39-
.parse()
40-
.unwrap(),
38+
format!("{}{}", status, remaining_items[0]).parse().unwrap(),
4139
remaining_items[1..].to_vec(),
4240
)
4341
}

2024/src/day_08/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<article class="day-desc"><h2>--- Day 8: Resonant Collinearity ---</h2><p>You find yourselves on the <a href="/2016/day/25">roof</a> of a top-secret Easter Bunny installation.</p>
2+
<p>While The Historians do their thing, you take a look at the familiar <em>huge antenna</em>. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand <span title="They could have imitated delicious chocolate, but the mediocre chocolate is WAY easier to imitate.">Imitation Mediocre</span> Chocolate as a Christmas gift! Unthinkable!</p>
3+
<p>Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific <em>frequency</em> indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:</p>
4+
<pre><code>............
5+
........0...
6+
.....0......
7+
.......0....
8+
....0.......
9+
......A.....
10+
............
11+
............
12+
........A...
13+
.........A..
14+
............
15+
............
16+
</code></pre>
17+
<p>The signal only applies its nefarious effect at specific <em>antinodes</em> based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.</p>
18+
<p>So, for these two antennas with frequency <code>a</code>, they create the two antinodes marked with <code>#</code>:</p>
19+
<pre><code>..........
20+
...#......
21+
..........
22+
....a.....
23+
..........
24+
.....a....
25+
..........
26+
......#...
27+
..........
28+
..........
29+
</code></pre>
30+
<p>Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:</p>
31+
<pre><code>..........
32+
...#......
33+
#.........
34+
....a.....
35+
........a.
36+
.....a....
37+
..#.......
38+
......#...
39+
..........
40+
..........
41+
</code></pre>
42+
<p>Antennas with different frequencies don't create antinodes; <code>A</code> and <code>a</code> count as different frequencies. However, antinodes <em>can</em> occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital <code>A</code> creates no antinodes but has a lowercase-<code>a</code>-frequency antinode at its location:</p>
43+
<pre><code>..........
44+
...#......
45+
#.........
46+
....a.....
47+
........a.
48+
.....a....
49+
..#.......
50+
......A...
51+
..........
52+
..........
53+
</code></pre>
54+
<p>The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost <code>A</code>-frequency antenna:</p>
55+
<pre><code>......#....#
56+
...#....0...
57+
....#0....#.
58+
..#....0....
59+
....0....#..
60+
.#....A.....
61+
...#........
62+
#......#....
63+
........A...
64+
.........A..
65+
..........#.
66+
..........#.
67+
</code></pre>
68+
<p>Because the topmost <code>A</code>-frequency antenna overlaps with a <code>0</code>-frequency antinode, there are <code><em>14</em></code> total unique locations that contain an antinode within the bounds of the map.</p>
69+
<p>Calculate the impact of the signal. <em>How many unique locations within the bounds of the map contain an antinode?</em></p>
70+
</article><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Watching over your shoulder as you work, one of The Historians asks if you took the effects of resonant harmonics into your calculations.</p>
71+
<p>Whoops!</p>
72+
<p>After updating your model, it turns out that an antinode occurs at <em>any grid position</em> exactly in line with at least two antennas of the same frequency, regardless of distance. This means that some of the new antinodes will occur at the position of each antenna (unless that antenna is the only one of its frequency).</p>
73+
<p>So, these three <code>T</code>-frequency antennas now create many antinodes:</p>
74+
<pre><code>T....#....
75+
...T......
76+
.T....#...
77+
.........#
78+
..#.......
79+
..........
80+
...#......
81+
..........
82+
....#.....
83+
..........
84+
</code></pre>
85+
<p>In fact, the three <code>T</code>-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! This brings the total number of antinodes in the above example to <code><em>9</em></code>.</p>
86+
<p>The original example now has <code><em>34</em></code> antinodes, including the antinodes that appear on every antenna:</p>
87+
<pre><code>##....#....#
88+
.#.#....0...
89+
..#.#0....#.
90+
..##...0....
91+
....0....#..
92+
.#...#A....#
93+
...#..#.....
94+
#....#.#....
95+
..#.....A...
96+
....#....A..
97+
.#........#.
98+
...#......##
99+
</code></pre>
100+
<p>Calculate the impact of the signal using this updated model. <em>How many unique locations within the bounds of the map contain an antinode?</em></p>
101+
</article>

2024/src/day_08/input.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
...........................A.............W........
2+
.......x..........AZ......P.........m......k..W...
3+
....v.....Z..K...V..........A.......R....f........
4+
.............d..........V.............2...........
5+
.........Z........d...V.....B....C.....e..........
6+
............Z.vA...........m...................s.W
7+
...x..o.....................ek....................
8+
...O.....VK..................R......B.............
9+
.........O..................my....kB..............
10+
.v...................y..........C........B.....z..
11+
xb.v..................................C..z........
12+
.........................2.ey.....................
13+
..K.......................y...................s...
14+
..........................................z.......
15+
.......................2.......R........z......F..
16+
O.....d..................D..k.........F...........
17+
..........O..........D.............s....E.........
18+
..o......9....................D........C..s.......
19+
.....o..r....................c...................m
20+
.......P..............................e...........
21+
..............1......................d............
22+
...................o...............3..............
23+
........................c.......24..........S.....
24+
....x..................c.............F4.........S.
25+
P............N..8.......W.D.......................
26+
.....K............1.8.............................
27+
.........P..............Q...M.....................
28+
9...................R........4...8.....0..........
29+
....n.........................F...................
30+
........Y...n......1......................3..J....
31+
.........................3...8....................
32+
...n...M............................0.......ja...S
33+
....f................................6.....S.....E
34+
....................i.........M...J...............
35+
...r..........q..........1......l..0.....L........
36+
.........f7....i.Nc......................j.......l
37+
..9....Y7......X.........Q...M5....J4...........3.
38+
.Y........NX..I............Q........L.............
39+
......Xw...nb.............0..............l6.......
40+
......b.....f....5..q.....................a..6....
41+
.......5..........iq.9.....p..........a...........
42+
........X........I................p...6...........
43+
..................N.............L.........j.......
44+
...b.7.......................p....Q......E........
45+
....Y....7......................p................j
46+
.......r..........................................
47+
.................i...................a............
48+
..w.........5.....................................
49+
......w........I..............J...................
50+
.w............r.....................lL............

0 commit comments

Comments
 (0)