@@ -14,28 +14,33 @@ class Solution : Solver {
14
14
15
15
var digits = Enumerable . Range ( 1 , 9 ) . ToArray ( ) ;
16
16
17
- var max = Enumerable . Repeat ( int . MinValue , 14 ) . ToArray ( ) ;
18
- var min = Enumerable . Repeat ( int . MaxValue , 14 ) . ToArray ( ) ;
19
- var stack = new Stack < int > ( ) ;
20
- var stmBlocks = input . Split ( "inp w\n " ) [ 1 ..] ; // the input has of 14 'blocks', reading one digit into w
17
+ var stmBlocks = input . Split ( "inp w\n " ) [ 1 ..] ; // The input has 14 code blocks, each dealing with one digit.
21
18
22
- // Extracts the numeric argument of a statement of the block at the given line
19
+ // Extracts the numeric argument of a statement:
23
20
var getArgFromLine = ( int iblock , Index iline ) =>
24
21
int . Parse ( stmBlocks [ iblock ] . Split ( '\n ' ) [ iline ] . Split ( ' ' ) [ ^ 1 ] ) ;
25
22
26
23
// The blocks define 7 pairs of `a`, `b` digits and a `shift` between them.
27
24
// The input is valid if for each pair the condition `a + shift = b` holds.
28
25
26
+ // A stack will contain the index of an `a` digit when we find it's corresponding `b`.
27
+ var stack = new Stack < int > ( ) ;
28
+
29
+ // We will fill up the result when `b` is found.
30
+ var max = Enumerable . Repeat ( int . MinValue , 14 ) . ToArray ( ) ;
31
+ var min = Enumerable . Repeat ( int . MaxValue , 14 ) . ToArray ( ) ;
32
+
29
33
for ( var j = 0 ; j < 14 ; j ++ ) {
30
34
if ( stmBlocks [ j ] . Contains ( "div z 1" ) ) {
31
35
// j points to an `a` digit.
32
36
stack . Push ( j ) ;
33
37
} else {
34
38
// j points to a `b` digit.
35
39
36
- var i = stack . Pop ( ) ; // The stack points to the index of the corresponding `a`.
40
+ // `a` is at i.
41
+ var i = stack . Pop ( ) ;
37
42
38
- // Shift is split into two, both blocks contain a part :
43
+ // A part of shift is hidden in each of the two blocks :
39
44
var shift = getArgFromLine ( i , ^ 4 ) + getArgFromLine ( j , 4 ) ;
40
45
41
46
// Find the best a and b so that the equation holds
0 commit comments