Skip to content

Commit e6cc8e4

Browse files
committed
Year 2025 Day 6
1 parent 96abe5c commit e6cc8e4

File tree

7 files changed

+90
-4
lines changed

7 files changed

+90
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
8282
| 3 | [Lobby](https://adventofcode.com/2025/day/3) | [Source](src/year2025/day03.rs) | 21 |
8383
| 4 | [Printing Department](https://adventofcode.com/2025/day/4) | [Source](src/year2025/day04.rs) | 177 |
8484
| 5 | [Cafeteria](https://adventofcode.com/2025/day/5) | [Source](src/year2025/day05.rs) | 20 |
85+
| 6 | [Trash Compactor](https://adventofcode.com/2025/day/6) | [Source](src/year2025/day06.rs) | 37 |
8586

8687
## 2024
8788

benches/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ benchmark!(year2024
9595
);
9696

9797
benchmark!(year2025
98-
day01, day02, day03, day04, day05
98+
day01, day02, day03, day04, day05, day06
9999
);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ library!(year2024 "Locate the Chief Historian in time for the big Christmas slei
7474
);
7575

7676
library!(year2025 "Finish the North Pole decorations in time for Christmas."
77-
day01, day02, day03, day04, day05
77+
day01, day02, day03, day04, day05, day06
7878
);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ run!(year2024
141141
);
142142

143143
run!(year2025
144-
day01, day02, day03, day04, day05
144+
day01, day02, day03, day04, day05, day06
145145
);

src/year2025/day06.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use crate::util::grid::*;
2+
use crate::util::parse::*;
3+
use crate::util::point::*;
4+
5+
pub fn parse(input: &str) -> &str {
6+
input
7+
}
8+
9+
pub fn part1(input: &str) -> u64 {
10+
let lines: Vec<_> = input.lines().rev().collect();
11+
let operations: Vec<_> = lines[0].split_ascii_whitespace().collect();
12+
let numbers: Vec<Vec<u64>> =
13+
lines[1..].iter().map(|line| line.iter_unsigned().collect()).collect();
14+
15+
operations
16+
.into_iter()
17+
.enumerate()
18+
.map(|(col, operation)| match operation {
19+
"+" => numbers.iter().map(|row| row[col]).sum::<u64>(),
20+
"*" => numbers.iter().map(|row| row[col]).product::<u64>(),
21+
_ => unreachable!(),
22+
})
23+
.sum()
24+
}
25+
26+
pub fn part2(input: &str) -> u64 {
27+
let grid = Grid::parse(input);
28+
let top = grid.height - 1;
29+
30+
let mut total = 0;
31+
let mut start = 0;
32+
let mut column = Vec::new();
33+
34+
while start < grid.width {
35+
let mut end = start + 1;
36+
while end < grid.width && grid[Point::new(end, top)] == b' ' {
37+
end += 1;
38+
}
39+
if end < grid.width {
40+
end -= 1;
41+
}
42+
43+
for x in start..end {
44+
let mut number = 0;
45+
46+
for y in 0..top {
47+
let point = Point::new(x, y);
48+
if grid[point] != b' ' {
49+
number = 10 * number + (grid[point] - b'0') as u64;
50+
}
51+
}
52+
53+
column.push(number);
54+
}
55+
56+
total += match grid[Point::new(start, top)] {
57+
b'+' => column.iter().sum::<u64>(),
58+
b'*' => column.iter().product::<u64>(),
59+
_ => unreachable!(),
60+
};
61+
start = end + 1;
62+
column.clear();
63+
}
64+
65+
total
66+
}

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ test!(year2024
8787
);
8888

8989
test!(year2025
90-
day01, day02, day03, day04, day05
90+
day01, day02, day03, day04, day05, day06
9191
);

tests/year2025/day06.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use aoc::year2025::day06::*;
2+
3+
const EXAMPLE: &str = "\
4+
123 328 51 64
5+
45 64 387 23
6+
6 98 215 314
7+
* + * + ";
8+
9+
#[test]
10+
fn part1_test() {
11+
let input = parse(EXAMPLE);
12+
assert_eq!(part1(input), 4277556);
13+
}
14+
15+
#[test]
16+
fn part2_test() {
17+
let input = parse(EXAMPLE);
18+
assert_eq!(part2(input), 3263827);
19+
}

0 commit comments

Comments
 (0)