Skip to content

Commit cab3703

Browse files
committed
day13 by AI (Claude 3.5). part two all by AI except parse_input
1 parent 1df207f commit cab3703

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/day13.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ pub fn part_one(input: &str) -> usize {
2727
}
2828

2929
pub fn part_two(input: &str) -> usize {
30-
0
30+
let (_, bus_ids) = parse_input(input);
31+
32+
let mut timestamp = 0;
33+
let mut step = 1;
34+
for (i, id) in bus_ids.iter().enumerate() {
35+
if *id == 0 {
36+
continue;
37+
}
38+
while (timestamp + i) % *id != 0 {
39+
timestamp += step;
40+
}
41+
step *= *id;
42+
}
43+
timestamp
3144
}
3245

3346
#[cfg(test)]
@@ -39,6 +52,6 @@ mod tests {
3952
fn example() {
4053
let input = read_example(13);
4154
assert_eq!(part_one(&input), 295);
42-
assert_eq!(part_two(&input), 0);
55+
assert_eq!(part_two(&input), 1068781);
4356
}
4457
}

0 commit comments

Comments
 (0)