Skip to content

Commit c16d8bf

Browse files
committed
Year 2025 Day 10
1 parent b6cc7ab commit c16d8bf

File tree

7 files changed

+87
-4
lines changed

7 files changed

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

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)