11use std:: cmp:: { max, min} ;
22use std:: collections:: HashMap ;
33use std:: iter:: { once, successors} ;
4+
5+ use aoclp:: positioning:: direction:: four_points:: Direction4 ;
46use aoclp:: positioning:: pt:: { rectangular_area, Pt } ;
57use aoclp:: solvers_impl:: input:: safe_get_input_as_many;
68use itertools:: Itertools ;
7- use aoclp:: positioning:: direction:: four_points:: Direction4 ;
89
910pub fn part_1 ( ) -> i64 {
1011 input ( )
@@ -28,14 +29,17 @@ pub fn part_2() -> i64 {
2829
2930 let safe = successors ( Some ( p) , |& p| ( p. y > safe_line) . then_some ( p + Direction4 :: Up ) )
3031 . filter ( |p| path. get ( p) . is_some_and ( |& step| step == PathStep :: LeftRight ) )
31- . count ( ) % 2 != 0 ;
32+ . count ( )
33+ % 2
34+ != 0 ;
3235 pt_safety. insert ( p, safe) ;
3336 safe
3437 } ;
3538 let mut safe_line = |a : Pt , b : Pt | -> bool {
3639 let displacement = Pt :: new ( ( b. x - a. x ) . signum ( ) , ( b. y - a. y ) . signum ( ) ) ;
37- successors ( Some ( a) , |& p| ( p != b) . then_some ( p + displacement) ) . chain ( Some ( b) )
38- . all ( |p| safe_pt ( p) )
40+ successors ( Some ( a) , |& p| ( p != b) . then_some ( p + displacement) )
41+ . chain ( Some ( b) )
42+ . all ( & mut safe_pt)
3943 } ;
4044 let mut safe_rectangle = |a : Pt , b : Pt | {
4145 let corners = [
@@ -90,7 +94,8 @@ fn build_path(red_tiles: &[Pt]) -> HashMap<Pt, PathStep> {
9094 let displacement = Pt :: new ( ( b. x - a. x ) . signum ( ) , ( b. y - a. y ) . signum ( ) ) ;
9195 successors ( Some ( ( a, PathStep :: Corner ) ) , move |& ( p, _) | {
9296 ( p != b) . then_some ( ( p + displacement, step) )
93- } ) . chain ( once ( ( b, PathStep :: Corner ) ) )
97+ } )
98+ . chain ( once ( ( b, PathStep :: Corner ) ) )
9499 } )
95100 . collect ( )
96101}
0 commit comments