Skip to content

Commit 49fabb3

Browse files
committed
chore: 2024 Day 11 Part 1
1 parent 147f834 commit 49fabb3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

2024/11/code.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,31 @@ import { readFileSync } from 'fs'
22
import { join } from 'path'
33

44
const data = readFileSync(join(__dirname, 'input.txt'), { encoding: 'utf-8', flag: 'r' })
5-
const lines = data.split('\n')
5+
let numbers = data.split(' ').map((number) => parseInt(number) || 0)
66

7-
function part1() {}
7+
function blink(numbers: number[]) {
8+
const result: number[] = []
9+
for (const number of numbers) {
10+
if (number === 0) {
11+
result.push(1)
12+
} else if (number.toString().length % 2 === 0) {
13+
const strNum = number.toString()
14+
const half = strNum.length / 2
15+
result.push(parseInt(strNum.slice(0, half)) || 0, parseInt(strNum.slice(half)) || 0)
16+
} else {
17+
result.push(number * 2024)
18+
}
19+
}
20+
return result
21+
}
22+
23+
function part1() {
24+
for (let i = 0; i < 25; i++) {
25+
numbers = blink(numbers)
26+
console.log('Blink #' + i, numbers.length)
27+
}
28+
return numbers.length
29+
}
830

931
function part2() {}
1032

2024/11/example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
125 17

2024/11/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 72 8949 0 981038 86311 246 7636740

bun.lockb

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)