@@ -3,11 +3,11 @@ use std::collections::BTreeSet;
33use std:: iter:: successors;
44
55use aoclp:: positioning:: direction:: four_points:: Direction4 ;
6+ use aoclp:: positioning:: direction:: { Direction , MovementDirection } ;
67use aoclp:: positioning:: pt:: { rectangular_area, Pt } ;
78use aoclp:: solvers_impl:: input:: safe_get_input_as_many;
8- use itertools:: { chain , Either , Itertools } ;
9+ use itertools:: Itertools ;
910use strum:: IntoEnumIterator ;
10- use aoclp:: positioning:: direction:: { Direction , MovementDirection } ;
1111
1212pub fn part_1 ( ) -> i64 {
1313 input ( )
@@ -61,7 +61,9 @@ fn build_red_zone(red_tiles: &[Pt]) -> impl Iterator<Item = Pt> + use<'_> {
6161
6262 let get_direction = |a : Pt , b : Pt | {
6363 let displacement = Pt :: new ( ( b. x - a. x ) . signum ( ) , ( b. y - a. y ) . signum ( ) ) ;
64- Direction4 :: iter ( ) . find ( |& d| d. displacement ( ) == displacement) . unwrap ( )
64+ Direction4 :: iter ( )
65+ . find ( |& d| d. displacement ( ) == displacement)
66+ . unwrap ( )
6567 } ;
6668
6769 red_tiles
@@ -75,26 +77,23 @@ fn build_red_zone(red_tiles: &[Pt]) -> impl Iterator<Item = Pt> + use<'_> {
7577 let direction = get_direction ( a, b) ;
7678 let turning_left = get_direction ( b, c) == direction. turn_left ( ) ;
7779
78- let red_zone_path = successors ( Some ( a) , move |& p| {
80+ let tail = if turning_left {
81+ vec ! [ ]
82+ } else {
83+ vec ! [
84+ b + direction. turn_left( ) ,
85+ b + direction + direction. turn_left( ) ,
86+ b + direction,
87+ ]
88+ } ;
89+
90+ successors ( Some ( a) , move |& p| {
7991 let next = p + direction;
8092 ( next != b) . then_some ( next)
8193 } )
82- . skip ( 1 )
83- . map ( move |p| p + ( direction. turn_left ( ) ) )
84- . collect_vec ( ) ;
85-
86- if turning_left {
87- Either :: Left ( red_zone_path. into_iter ( ) )
88- } else {
89- Either :: Right ( chain (
90- red_zone_path,
91- vec ! [
92- b + direction. turn_left( ) ,
93- b + direction + direction. turn_left( ) ,
94- b + direction,
95- ] ,
96- ) )
97- }
94+ . skip ( 1 )
95+ . map ( move |p| p + ( direction. turn_left ( ) ) )
96+ . chain ( tail)
9897 } )
9998}
10099
0 commit comments