Skip to content

Commit d496a75

Browse files
committed
Adjusts comment
1 parent fb5cf3d commit d496a75

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

2019/16/part-two.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const { partTwoInput } = require('./input');
33
const offset = parseInt(partTwoInput.slice(0, 7).join(''), 10);
44
const slice_to_iterate = partTwoInput.slice(offset);
55
for (let j = 0; j < 100; j++) {
6+
// We don't need to do anything with the last number so start at 2nd the last
67
for (let i = slice_to_iterate.length - 2; i >= 0; i--) {
78
slice_to_iterate[i] = (slice_to_iterate[i + 1] + slice_to_iterate[i]) % 10;
89
}
910
}
1011

1112
console.log('8 digits:', slice_to_iterate.slice(0, 8).join(''));
1213

13-
1414
/*
1515
1616
Here's the trick:
@@ -57,33 +57,38 @@ and loop up.
5757
5858
Consider
5959
60-
n + ... = x_n n + x_n-1 = x_n
61-
d + c + b + a = x_4 d + x_3 = x_4
62-
c + b + a = x_3 => c + x_2 = x_3
63-
b + a = x_2 b + x_1 = x_2
64-
a = x_1 a = x_1
65-
66-
Let x_n = D_i..D_1D_0 , where D_n is a single digit.
67-
(x_n)mod 10 = D_0
68-
Let `l + x_n` be the next line up we want to add. So l is a single digit number.
69-
We only care about the last digit of all that addition, so I want to show that
70-
(l + x_n)mod 10 = (l + D_0)mod 10.
71-
From the "Addition Property" of modular arithmetic, we know that
72-
(a + b)mod_n = [(a)mod_n + (b)mod_n]mod_n
60+
n + ... = x_n n + x_n-1 = x_n
61+
d + c + b + a = x_4 d + x_3 = x_4
62+
c + b + a = x_3 => c + x_2 = x_3
63+
b + a = x_2 b + x_1 = x_2
64+
a = x_1 a = x_1
65+
66+
Let `x_n` = `D_i..D_1D_0`, where `D_n` is a single digit.
7367
74-
So, expanding (l + x_n)mod 10 is
68+
Clearly `(x_n)mod 10 = D_0`, aka the last digit.
7569
76-
(l + x_n)mod_10 = ((l)mod_10 + (x_n)mod_10)mod_10.
70+
Let `l + x_n` be the next line up we want to add. So `l` is a single digit number.
7771
78-
Well (l)mod_10 is just l, since l is less than 10.
72+
I'm saying we should only care about the last digit of all that addition, so I want to show that
7973
80-
= ((l) + (x_n)mod_10)mod_10.
74+
(l + x_n)mod 10 = (l + D_0)mod 10.
75+
76+
From the "Addition Property" of modular arithmetic, we know that
8177
82-
Add (x_n)mod_10 = D_0
78+
(a + b)mod_n = [(a)mod_n + (b)mod_n]mod_n
8379
84-
= (l + D0 )mod_10.
80+
So, expanding `(l + x_n)mod 10` is
8581
86-
QED.
82+
(l + x_n)mod_10 = ((l)mod_10 + (x_n)mod_10)mod_10.
83+
84+
# Well `(l)mod_10` is just `l`, since `l` is less than 10 (aka a single digit).
85+
86+
(l + x_n)mod_10 = ((l) + (x_n)mod_10)mod_10.
87+
88+
# Add (x_n)mod_10 = D_0
89+
90+
(l + x_n)mod_10 = (l + D0 )mod_10.
8791
92+
QED ∎
8893
8994
*/

0 commit comments

Comments
 (0)