mirror of
https://github.com/seigler/aoc2024
synced 2025-07-26 00:36:10 +00:00
day 14 cleaner
This commit is contained in:
parent
992ab32a04
commit
4803b87dad
1 changed files with 17 additions and 19 deletions
|
@ -24,26 +24,24 @@ const part1 = (rawInput: string) => {
|
|||
}
|
||||
|
||||
const part2 = (rawInput: string) => {
|
||||
(async () => {
|
||||
const input = parseInput(rawInput)
|
||||
const width = 101
|
||||
const height = 103
|
||||
for (let i = 0; i < 20000; i++) {
|
||||
const canvas: string[][] = []
|
||||
for (let y = 0; y < height; y++) {
|
||||
canvas.push(" ".repeat(width).split(''))
|
||||
}
|
||||
input.forEach(([ix, iy, dx, dy]) => {
|
||||
const destx = (ix + (width + dx) * i) % width
|
||||
const desty = (iy + (height + dy) * i) % height
|
||||
canvas[desty][destx] = "#"
|
||||
})
|
||||
if (canvas.some(line => line.join('').includes("##########"))) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
console.log(`\nTIME: ${i} seconds\n${canvas.map(line => console.log(line.join(""))).join('\n')}`)
|
||||
}
|
||||
const input = parseInput(rawInput)
|
||||
const width = 101
|
||||
const height = 103
|
||||
for (let i = 0; i < width * height; i++) {
|
||||
const canvas: string[][] = []
|
||||
for (let y = 0; y < height; y++) {
|
||||
canvas.push(" ".repeat(width).split(''))
|
||||
}
|
||||
})()
|
||||
input.forEach(([ix, iy, dx, dy]) => {
|
||||
const destx = (ix + (width + dx) * i) % width
|
||||
const desty = (iy + (height + dy) * i) % height
|
||||
canvas[desty][destx] = "#"
|
||||
})
|
||||
if (canvas.some(line => line.join('').includes("##########"))) {
|
||||
console.log(`\nTIME: ${i} seconds\n${canvas.map(line => console.log(line.join(""))).join('\n')}`)
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue