Skip to content

Commit 09b9813

Browse files
committed
[2025] Day 1 first solutions
1 parent 9765c4a commit 09b9813

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

README.md

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

66
## [2025](https://adventofcode.com/2025) [![aoc_2025](https://github.com/connorslade/advent-of-code/actions/workflows/aoc_2025.yml/badge.svg)](https://github.com/connorslade/advent-of-code/actions/workflows/aoc_2025.yml)
77

8+
- [Day 01: Secret Entrance](aoc_2025/src/day_01.rs)
89
<!-- MARKER -->
910

1011
## [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_01.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use common::{Answer, solution};
2+
3+
solution!("Secret Entrance", 1);
4+
5+
fn part_a(input: &str) -> Answer {
6+
let mut pos = 50;
7+
let mut out = 0;
8+
9+
for line in input.trim().lines() {
10+
let num = line[1..].parse::<u32>().unwrap();
11+
match line.as_bytes()[0] {
12+
b'L' => {
13+
if num % 100 > pos {
14+
pos = 100 - (num % 100 - pos);
15+
} else {
16+
pos -= num;
17+
}
18+
}
19+
b'R' => pos = (pos + num) % 100,
20+
_ => unreachable!(),
21+
}
22+
23+
out += (pos == 0) as u64;
24+
}
25+
26+
out.into()
27+
}
28+
29+
fn part_b(input: &str) -> Answer {
30+
let mut pos = 50;
31+
let mut out = 0;
32+
33+
for line in input.trim().lines() {
34+
let num = line[1..].parse::<u32>().unwrap();
35+
match line.as_bytes()[0] {
36+
b'L' => {
37+
for _ in 0..num {
38+
if pos == 0 {
39+
pos = 99;
40+
} else {
41+
pos -= 1;
42+
}
43+
44+
out += (pos == 0) as u64;
45+
}
46+
}
47+
b'R' => {
48+
for _ in 0..num {
49+
if pos == 99 {
50+
pos = 0;
51+
} else {
52+
pos += 1;
53+
}
54+
55+
out += (pos == 0) as u64;
56+
}
57+
}
58+
_ => unreachable!(),
59+
}
60+
}
61+
62+
out.into()
63+
}
64+
65+
#[cfg(test)]
66+
mod test {
67+
use indoc::indoc;
68+
69+
const CASE: &str = indoc! {"
70+
L68
71+
L30
72+
R48
73+
L5
74+
R60
75+
L55
76+
L1
77+
L99
78+
R14
79+
L82
80+
81+
"};
82+
83+
#[test]
84+
fn part_a() {
85+
assert_eq!(super::part_a(CASE), 3.into());
86+
}
87+
88+
#[test]
89+
fn part_b() {
90+
assert_eq!(super::part_b(CASE), 6.into());
91+
}
92+
}

aoc_2025/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use common::Solution;
22

3+
mod day_01;
34
// [import_marker]
45

56
pub const SOLUTIONS: &[Solution] = &[
7+
day_01::SOLUTION,
68
// [list_marker]
79
];

0 commit comments

Comments
 (0)