Skip to content

Commit eb06ed5

Browse files
committed
[2025] Day 3 solve + cleanup forgot to commit right after solving oops
1 parent c261553 commit eb06ed5

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Thank you to [Eric Wastl](http://was.tl) for running this incredible yearly even
77

88
- [Day 01: Secret Entrance](aoc_2025/src/day_01.rs)
99
- [Day 02: Gift Shop](aoc_2025/src/day_02.rs)
10+
- [Day 03: Lobby](aoc_2025/src/day_03.rs)
1011
<!-- MARKER -->
1112

1213
## [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_02.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ fn count_invalid(input: &str, is_invalid: fn(u64) -> bool) -> u64 {
4343

4444
for range in input.split(',') {
4545
let (start, end) = range.split_once('-').unwrap();
46-
let start = start.parse::<u64>().unwrap();
47-
let end = end.parse::<u64>().unwrap();
46+
let start = start.parse().unwrap();
47+
let end = end.parse().unwrap();
4848

4949
for id in start..=end {
5050
count += is_invalid(id) as u64 * id;

aoc_2025/src/day_03.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use common::{Answer, solution};
2+
3+
solution!("Lobby", 3);
4+
5+
fn part_a(input: &str) -> Answer {
6+
solve(input, 2).into()
7+
}
8+
9+
fn part_b(input: &str) -> Answer {
10+
solve(input, 12).into()
11+
}
12+
13+
fn solve(input: &str, n: usize) -> u64 {
14+
let mut out = 0;
15+
for bank in input.trim().lines() {
16+
let digits = bank
17+
.chars()
18+
.map(|x| x.to_digit(10).unwrap() as u8)
19+
.collect::<Vec<_>>();
20+
out += joltage(&digits, n);
21+
}
22+
23+
out
24+
}
25+
26+
fn joltage(digits: &[u8], n: usize) -> u64 {
27+
let mut num = 0;
28+
let mut last_used = 0;
29+
30+
for bat in 0..n {
31+
let size = digits.len() - (n - 1 - bat) - last_used;
32+
let slice = &digits[last_used..(last_used + size).min(digits.len())];
33+
34+
for i in (0..=9).rev() {
35+
if let Some(idx) = slice.iter().position(|x| *x == i) {
36+
last_used += idx + 1;
37+
num = num * 10 + i as u64;
38+
break;
39+
}
40+
}
41+
}
42+
43+
num
44+
}
45+
46+
#[cfg(test)]
47+
mod test {
48+
use indoc::indoc;
49+
50+
const CASE: &str = indoc! {"
51+
987654321111111
52+
811111111111119
53+
234234234234278
54+
818181911112111
55+
"};
56+
57+
#[test]
58+
fn part_a() {
59+
assert_eq!(super::part_a(CASE), 357.into());
60+
}
61+
62+
#[test]
63+
fn part_b() {
64+
assert_eq!(super::part_b(CASE), 3121910778619_u64.into());
65+
}
66+
}

aoc_2025/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use common::Solution;
22

33
mod day_01;
44
mod day_02;
5+
mod day_03;
56
// [import_marker]
67

78
pub const SOLUTIONS: &[Solution] = &[
89
day_01::SOLUTION,
910
day_02::SOLUTION,
11+
day_03::SOLUTION,
1012
// [list_marker]
1113
];

0 commit comments

Comments
 (0)