File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -51,23 +51,28 @@ impl Day23 {
5151 #[ must_use]
5252 pub fn part1 ( & self ) -> u32 {
5353 let mut count = 0 ;
54- for n1 in 0 ..self . nodes . len ( ) {
54+
55+ // 19 = b't' - b'a'
56+ for n1 in 19 * 26 ..20 * 26 {
5557 for n2 in self . neighbors ( n1) {
56- if n2 > n1 {
57- break ;
58+ // Ensure the combination is only counted once if the second node also starts with t
59+ if n2 / 26 == 19 && n2 >= n1 {
60+ continue ;
5861 }
62+
5963 for n3 in Self :: iter ( Self :: intersect ( self . nodes [ n1] , self . nodes [ n2] ) ) {
60- if n3 > n2 {
64+ if n3 >= n2 {
6165 break ;
6266 }
63-
64- // 19 = b't' - b'a'
65- if n1 / 26 == 19 || n2 / 26 == 19 || n3 / 26 == 19 {
66- count += 1 ;
67+ if n3 / 26 == 19 && n3 >= n1 {
68+ continue ;
6769 }
70+
71+ count += 1 ;
6872 }
6973 }
7074 }
75+
7176 count
7277 }
7378
You can’t perform that action at this time.
0 commit comments