Skip to content

Commit d2444e5

Browse files
committed
day23 part 2
1 parent 6a6c20b commit d2444e5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Different scripts for day 25,
220220
| 20 | S/H | picture matching/pattern search |
221221
| 21 | M/S | analyze insets |
222222
| 22 | S/S | cards array iteration |
223-
| 23 | S/- | array iteration |
223+
| 23 | S/S | array iteration |
224224
| 24 | S/S | hex flip/life game simulation |
225225
| 25 | S/- | number iteration |
226226

lib/2020/day23.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const MAX = 9
1+
let MAX = 9
22

33
module.exports = function(part, data) {
44
const numbers = data.split('').map(x => +x)
@@ -18,13 +18,32 @@ module.exports = function(part, data) {
1818
}
1919

2020
result = []
21-
let n = 8
21+
let n = MAX - 1
2222
while (n--) {
2323
cur = cur.next
2424
result.push(cur.v)
2525
}
2626
result = result.join('')
2727
} else {
28+
const nmax = 1000000
29+
let prev = nodes[numbers[MAX - 1]]
30+
for (let i = MAX + 1; i <= nmax; i++) {
31+
prev.next = nodes[i] = { v: i }
32+
prev = prev.next
33+
}
34+
nodes[nmax].next = nodes[numbers[0]]
35+
MAX = nmax
36+
37+
let moves = 10000000
38+
while (moves--) {
39+
if (!(moves % 10000)) console.log(moves)
40+
41+
update(cur, nodes)
42+
cur = cur.next
43+
}
44+
45+
result = nodes[1].next.v * nodes[1].next.next.v
46+
console.log(nodes[1].next.v, nodes[1].next.next.v)
2847
}
2948
console.log(result)
3049
}

0 commit comments

Comments
 (0)