Skip to content

Commit 8c44ff0

Browse files
committed
Year 2025 Day 10
1 parent b6cc7ab commit 8c44ff0

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
8686
| 7 | [Laboratories](https://adventofcode.com/2025/day/7) | [Source](src/year2025/day07.rs) | 5 |
8787
| 8 | [Playground](https://adventofcode.com/2025/day/8) | [Source](src/year2025/day08.rs) | 527 |
8888
| 9 | [Movie Theater](https://adventofcode.com/2025/day/9) | [Source](src/year2025/day09.rs) | 668 |
89+
| 10 | [Factory](https://adventofcode.com/2025/day/10) | [Source](src/year2025/day10.rs) | 126* |
8990

9091
## 2024
9192

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, day06, day07, day08, day09
98+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10
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, day06, day07, day08, day09
77+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10
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, day06, day07, day08, day09
144+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10
145145
);

src/year2025/day10.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! # Factory
2+
use crate::util::bitset::*;
3+
use crate::util::parse::*;
4+
5+
type Machine = (u64, Vec<u64>, Vec<u64>);
6+
7+
pub fn parse(input: &str) -> Vec<Machine> {
8+
input
9+
.lines()
10+
.map(|line| {
11+
let tokens: Vec<_> = line.split_ascii_whitespace().collect();
12+
let first = tokens[0].as_bytes();
13+
let last = tokens.len() - 1;
14+
15+
let lights = first[1..first.len() - 1]
16+
.iter()
17+
.rev()
18+
.fold(0, |acc, &b| (acc << 1) | u64::from(b == b'#'));
19+
let buttons = tokens[1..last]
20+
.iter()
21+
.map(|token| token.iter_unsigned::<u64>().fold(0, |acc, i| acc | (1 << i)))
22+
.collect();
23+
let joltages = tokens[last].iter_unsigned::<u64>().collect();
24+
25+
(lights, buttons, joltages)
26+
})
27+
.collect()
28+
}
29+
30+
pub fn part1(input: &[Machine]) -> u32 {
31+
input
32+
.iter()
33+
.map(|(lights, buttons, _)| {
34+
let limit = 1 << buttons.len();
35+
let mut set = 0;
36+
37+
loop {
38+
set += 1;
39+
let mut n = (1 << set) - 1;
40+
41+
while n < limit {
42+
if *lights == n.biterator().fold(0, |acc, i| acc ^ buttons[i]) {
43+
return set;
44+
}
45+
n = next_same_bits(n);
46+
}
47+
}
48+
})
49+
.sum()
50+
}
51+
52+
pub fn part2(_input: &[Machine]) -> u32 {
53+
123456789
54+
}
55+
56+
fn next_same_bits(n: i32) -> i32 {
57+
let smallest = n & -n;
58+
let ripple = n + smallest;
59+
let ones = n ^ ripple;
60+
let next = (ones >> 2) / smallest;
61+
ripple | next
62+
}

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, day06, day07, day08, day09
90+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10
9191
);

tests/year2025/day10.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use aoc::year2025::day10::*;
2+
3+
const EXAMPLE: &str = "\
4+
[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7}
5+
[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2}
6+
[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}";
7+
8+
#[test]
9+
fn part1_test() {
10+
let input = parse(EXAMPLE);
11+
assert_eq!(part1(&input), 7);
12+
}
13+
14+
#[test]
15+
fn part2_test() {
16+
// No working part two yet.
17+
}

0 commit comments

Comments
 (0)