Skip to content

Commit 9745fb1

Browse files
committed
[2025] Finish day 12
and thats all for aoc 2025
1 parent 5782dbc commit 9745fb1

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Thank you to [Eric Wastl](http://was.tl) for running this incredible yearly even
1616
- [Day 09: Movie Theater](aoc_2025/src/day_09.rs)
1717
- [Day 10: Factory](aoc_2025/src/day_10.rs)
1818
- [Day 11: Reactor](aoc_2025/src/day_11.rs)
19+
- [Day 12: Christmas Tree Farm](aoc_2025/src/day_12.rs)
1920
<!-- MARKER -->
2021

2122
## [2024](https://adventofcode.com/2024) [![aoc_2024](https://github.com/connorslade/advent-of-code/actions/workflows/aoc_2024.yml/badge.svg)](https://github.com/connorslade/advent-of-code/actions/workflows/aoc_2024.yml)

aoc_2025/src/day_12.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
use common::{Answer, solution};
2+
use nd_vec::{Vec2, vector};
3+
4+
solution!("Christmas Tree Farm", 12);
5+
6+
#[derive(Debug)]
7+
struct Tree {
8+
size: Vec2<u32>,
9+
counts: Vec<u32>,
10+
}
11+
12+
fn part_a(input: &str) -> Answer {
13+
let (presents, trees) = parse(input);
14+
15+
(trees.iter())
16+
.filter(|tree| {
17+
(presents.iter().zip(tree.counts.iter()))
18+
.map(|(present, count)| *present as u32 * *count)
19+
.sum::<u32>()
20+
<= tree.size.x() * tree.size.y()
21+
})
22+
.count()
23+
.into()
24+
}
25+
26+
fn part_b(_input: &str) -> Answer {
27+
Answer::Unimplemented
28+
}
29+
30+
fn parse(input: &str) -> (Vec<usize>, Vec<Tree>) {
31+
let (presents_raw, trees_raw) = input.rsplit_once("\n\n").unwrap();
32+
33+
let mut presents = Vec::new();
34+
for present in presents_raw.split("\n\n") {
35+
let raw = present[present.find('\n').unwrap()..].trim();
36+
presents.push(raw.chars().filter(|x| *x == '#').count());
37+
}
38+
39+
let mut trees = Vec::new();
40+
for tree in trees_raw.lines() {
41+
let (size, counts) = tree.split_once(": ").unwrap();
42+
43+
let (width, height) = size.split_once('x').unwrap();
44+
let size = vector!(width.parse().unwrap(), height.parse().unwrap());
45+
46+
let counts = counts
47+
.split_whitespace()
48+
.map(|x| x.parse::<u32>().unwrap())
49+
.collect::<Vec<_>>();
50+
51+
trees.push(Tree { size, counts });
52+
}
53+
54+
(presents, trees)
55+
}
56+
57+
#[cfg(test)]
58+
mod test {
59+
use indoc::indoc;
60+
61+
const CASE: &str = indoc! {"
62+
0:
63+
###
64+
##.
65+
##.
66+
67+
1:
68+
###
69+
##.
70+
.##
71+
72+
2:
73+
.##
74+
###
75+
##.
76+
77+
3:
78+
##.
79+
###
80+
##.
81+
82+
4:
83+
###
84+
#..
85+
###
86+
87+
5:
88+
###
89+
.#.
90+
###
91+
92+
4x4: 0 0 0 0 2 0
93+
12x5: 1 0 1 0 2 2
94+
12x5: 1 0 1 0 5 2
95+
"};
96+
97+
#[test]
98+
fn part_a() {
99+
assert_eq!(super::part_a(CASE), 2.into());
100+
}
101+
102+
#[test]
103+
fn part_b() {
104+
assert_eq!(super::part_b(CASE), ().into());
105+
}
106+
}

aoc_2025/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod day_08;
1111
mod day_09;
1212
mod day_10;
1313
mod day_11;
14+
mod day_12;
1415
// [import_marker]
1516

1617
pub const SOLUTIONS: &[Solution] = &[
@@ -25,5 +26,6 @@ pub const SOLUTIONS: &[Solution] = &[
2526
day_09::SOLUTION,
2627
day_10::SOLUTION,
2728
day_11::SOLUTION,
29+
day_12::SOLUTION,
2830
// [list_marker]
2931
];

0 commit comments

Comments
 (0)