Skip to content

Commit b09d32b

Browse files
committed
2024 day 11 part 1
1 parent 18d1ae2 commit b09d32b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2024/js/day11.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const stones = '572556 22 0 528 4679021 1 10725 2790'.split(' ').map(s => Number(s));
2+
3+
const blinkStone = (stone) => {
4+
if (stone == 0) return [1];
5+
const str = `${stone}`;
6+
if (str.length % 2 == 0) {
7+
const middle = str.length / 2;
8+
const [left, right] = [str.substring(0, middle), str.substring(middle)];
9+
return [Number(left), Number(right)];
10+
}
11+
return [2024 * stone];
12+
};
13+
14+
const blink = (stones) => stones.flatMap(s => blinkStone(s));
15+
16+
let afterBlink = stones;
17+
for (let i = 0; i < 25; i++) {
18+
afterBlink = blink(afterBlink);
19+
}
20+
console.log(afterBlink.length);

0 commit comments

Comments
 (0)