File tree Expand file tree Collapse file tree 3 files changed +95
-0
lines changed
Expand file tree Collapse file tree 3 files changed +95
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11use common:: Solution ;
22
3+ mod day_01;
34// [import_marker]
45
56pub const SOLUTIONS : & [ Solution ] = & [
7+ day_01:: SOLUTION ,
68 // [list_marker]
79] ;
You can’t perform that action at this time.
0 commit comments