File tree Expand file tree Collapse file tree 1 file changed +17
-19
lines changed Expand file tree Collapse file tree 1 file changed +17
-19
lines changed Original file line number Diff line number Diff line change 11use crate :: solutions:: Solution ;
2- use std:: collections:: { HashMap , HashSet } ;
2+ use itertools:: Itertools ;
3+ use std:: collections:: HashMap ;
34
45pub struct Day23 ;
56
@@ -19,25 +20,22 @@ impl Solution for Day23 {
1920 } )
2021 . collect ( ) ;
2122
22- let mut sets: HashSet < [ & str ; 3 ] > = HashSet :: new ( ) ;
23+ connections
24+ . iter ( )
25+ . flat_map ( |( a, b) | {
26+ let a_neighbours = neighbours. get ( a) . unwrap ( ) ;
27+ let b_neighbours = neighbours. get ( b) . unwrap ( ) ;
2328
24- connections. iter ( ) . for_each ( |( a, b) | {
25- let a_neighbours = neighbours. get ( a) . unwrap ( ) ;
26- let b_neighbours = neighbours. get ( b) . unwrap ( ) ;
27-
28- let intersection: Vec < _ > = a_neighbours
29- . iter ( )
30- . filter ( |x| b_neighbours. contains ( x) )
31- . collect ( ) ;
32-
33- intersection. iter ( ) . for_each ( |c| {
34- let mut set = [ * a, * b, * c] ;
35- set. sort ( ) ;
36- sets. insert ( set) ;
37- } ) ;
38- } ) ;
39-
40- sets. iter ( )
29+ a_neighbours
30+ . iter ( )
31+ . filter ( |x| b_neighbours. contains ( x) )
32+ . map ( |c| {
33+ let mut set = [ * a, * b, * c] ;
34+ set. sort ( ) ;
35+ set
36+ } )
37+ } )
38+ . unique ( )
4139 . filter ( |set| set. iter ( ) . any ( |c| c. starts_with ( "t" ) ) )
4240 . count ( )
4341 . to_string ( )
You can’t perform that action at this time.
0 commit comments