File tree 1 file changed +17
-19
lines changed
1 file changed +17
-19
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: solutions:: Solution ;
2
- use std:: collections:: { HashMap , HashSet } ;
2
+ use itertools:: Itertools ;
3
+ use std:: collections:: HashMap ;
3
4
4
5
pub struct Day23 ;
5
6
@@ -19,25 +20,22 @@ impl Solution for Day23 {
19
20
} )
20
21
. collect ( ) ;
21
22
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 ( ) ;
23
28
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 ( )
41
39
. filter ( |set| set. iter ( ) . any ( |c| c. starts_with ( "t" ) ) )
42
40
. count ( )
43
41
. to_string ( )
You can’t perform that action at this time.
0 commit comments