File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ rust-version = "1.81.0"
88aoclp = { path = " ../aoclp" }
99bit-vec = { workspace = true }
1010clap = { workspace = true , features = [" derive" ] }
11+ fancy-regex = { workspace = true }
1112itertools = { workspace = true }
1213paste = { workspace = true }
1314primes = { workspace = true }
Original file line number Diff line number Diff line change @@ -3,21 +3,43 @@ use std::str::FromStr;
33
44use aoclp:: num:: Integer ;
55use aoclp:: solvers_impl:: input:: safe_get_input_as_one_vec;
6+ use fancy_regex:: Regex ;
67use itertools:: Itertools ;
78
89pub fn part_1 ( ) -> usize {
10+ match be_fast ( ) {
11+ true => sum_fast ( invalid) ,
12+ false => sum_slow ( Regex :: new ( r"^(\d+)\1$" ) . unwrap ( ) ) ,
13+ }
14+ }
15+
16+ pub fn part_2 ( ) -> usize {
17+ match be_fast ( ) {
18+ true => sum_fast ( invalid) ,
19+ false => sum_slow ( Regex :: new ( r"^(\d+)\1+$" ) . unwrap ( ) ) ,
20+ }
21+ }
22+
23+ fn be_fast ( ) -> bool {
24+ true
25+ }
26+
27+ fn sum_fast < P > ( mut pred : P ) -> usize
28+ where
29+ P : FnMut ( usize ) -> bool ,
30+ {
931 input ( )
1032 . into_iter ( )
1133 . flat_map ( |range| range. into_iter ( ) )
12- . filter ( |id| invalid ( * id) )
34+ . filter ( |id| pred ( * id) )
1335 . sum ( )
1436}
1537
16- pub fn part_2 ( ) -> usize {
38+ fn sum_slow ( re : Regex ) -> usize {
1739 input ( )
1840 . into_iter ( )
1941 . flat_map ( |range| range. into_iter ( ) )
20- . filter ( |id| invalid_fancy ( * id ) )
42+ . filter ( |id| re . is_match ( & id . to_string ( ) ) . unwrap ( ) )
2143 . sum ( )
2244}
2345
You can’t perform that action at this time.
0 commit comments