File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
aoclp_solutions/src/y2025 Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ pub mod forth;
55pub mod looping;
66pub mod positioning;
77pub mod solvers_impl;
8+ pub mod str;
89
910pub type Error = anyhow:: Error ;
1011pub type Result < T > = anyhow:: Result < T > ;
Original file line number Diff line number Diff line change 1+ use std:: str:: FromStr ;
2+
3+ pub trait StrHelper {
4+ fn split_parse_at < T , U > ( & self , pos : usize ) -> ( T , U )
5+ where
6+ T : FromStr ,
7+ U : FromStr ,
8+ <T as FromStr >:: Err : std:: fmt:: Debug ,
9+ <U as FromStr >:: Err : std:: fmt:: Debug ;
10+ }
11+
12+ impl < S > StrHelper for S
13+ where
14+ S : AsRef < str > ,
15+ {
16+ fn split_parse_at < T , U > ( & self , pos : usize ) -> ( T , U )
17+ where
18+ T : FromStr ,
19+ U : FromStr ,
20+ <T as FromStr >:: Err : std:: fmt:: Debug ,
21+ <U as FromStr >:: Err : std:: fmt:: Debug ,
22+ {
23+ let s = self . as_ref ( ) ;
24+ ( s[ 0 ..pos] . parse ( ) . unwrap ( ) , s[ pos..] . parse ( ) . unwrap ( ) )
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use std::str::FromStr;
33
44use aoclp:: anyhow:: anyhow;
55use aoclp:: solvers_impl:: input:: safe_get_input_as_many;
6+ use aoclp:: str:: StrHelper ;
67
78pub fn part_1 ( ) -> usize {
89 moves ( ) . filter ( |dial| * dial == 0 ) . count ( )
@@ -81,8 +82,7 @@ impl FromStr for Rotation {
8182 type Err = aoclp:: Error ;
8283
8384 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
84- let direction: RotationDirection = s[ 0 ..1 ] . parse ( ) ?;
85- let clicks: i64 = s[ 1 ..] . parse ( ) ?;
85+ let ( direction, clicks) = s. split_parse_at ( 1 ) ;
8686 Ok ( Self { direction, clicks } )
8787 }
8888}
You can’t perform that action at this time.
0 commit comments