File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -15,16 +15,17 @@ impl Solution for Day17 {
15
15
fn part_two ( & self , input : & str ) -> String {
16
16
let ( _, program) = self . parse ( input) ;
17
17
18
- let mut i = 0 ;
19
- loop {
18
+ for i in 0 .. {
20
19
let mut register = RegisterBuilder :: default ( ) . a ( i) . build ( ) ;
21
20
22
21
if program. execute_and_watch ( & mut register) {
23
22
return i. to_string ( ) ;
24
23
}
25
24
26
- i += 1 ;
25
+ println ! ( "{}" , i ) ;
27
26
}
27
+
28
+ unreachable ! ( )
28
29
}
29
30
}
30
31
@@ -113,9 +114,21 @@ impl Program {
113
114
& mut output,
114
115
) ;
115
116
117
+ if output. is_empty ( ) {
118
+ continue ;
119
+ }
120
+
116
121
if expected == output {
117
122
return true ;
118
123
}
124
+
125
+ if expected. len ( ) <= output. len ( ) {
126
+ return false ;
127
+ }
128
+
129
+ if expected[ 0 ..output. len ( ) ] != output {
130
+ return false ;
131
+ }
119
132
}
120
133
121
134
false
You can’t perform that action at this time.
0 commit comments