mirror of
https://github.com/seigler/aoc2024
synced 2025-07-26 00:36:10 +00:00
day 14, fun but strange
This commit is contained in:
parent
6106f22c63
commit
992ab32a04
4 changed files with 101 additions and 11 deletions
|
@ -209,10 +209,10 @@
|
|||
},
|
||||
{
|
||||
"part1": {
|
||||
"solved": false,
|
||||
"result": null,
|
||||
"solved": true,
|
||||
"result": "224554908",
|
||||
"attempts": [],
|
||||
"time": null
|
||||
"time": 1.492066
|
||||
},
|
||||
"part2": {
|
||||
"solved": false,
|
||||
|
|
16
README.md
16
README.md
|
@ -24,7 +24,7 @@
|
|||
[](src/day11)
|
||||
[](src/day12)
|
||||
[](src/day13)
|
||||

|
||||
[](src/day14)
|
||||

|
||||

|
||||

|
||||
|
@ -153,16 +153,16 @@ Both parts: 387.236ms
|
|||
|
||||
```
|
||||
Day 13
|
||||
Time part 1: -
|
||||
Time part 2: 7.731ms
|
||||
Both parts: 7.731ms
|
||||
Time part 1: 1.095ms
|
||||
Time part 2: 0.818ms
|
||||
Both parts: 1.913ms
|
||||
```
|
||||
|
||||
```
|
||||
Day 14
|
||||
Time part 1: -
|
||||
Time part 1: 1.507ms
|
||||
Time part 2: -
|
||||
Both parts: -
|
||||
Both parts: 1.507ms
|
||||
```
|
||||
|
||||
```
|
||||
|
@ -243,8 +243,8 @@ Both parts: -
|
|||
```
|
||||
|
||||
```
|
||||
Total stars: 26/50
|
||||
Total time: 38909.996ms
|
||||
Total stars: 27/50
|
||||
Total time: 38905.685ms
|
||||
```
|
||||
|
||||
<!--/RESULTS-->
|
||||
|
|
9
src/day14/README.md
Normal file
9
src/day14/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# 🎄 Advent of Code 2024 - day 14 🎄
|
||||
|
||||
## Info
|
||||
|
||||
Task description: [link](https://adventofcode.com/2024/day/14)
|
||||
|
||||
## Notes
|
||||
|
||||
...
|
81
src/day14/index.ts
Normal file
81
src/day14/index.ts
Normal file
|
@ -0,0 +1,81 @@
|
|||
import run from "aocrunner"
|
||||
|
||||
const parseInput = (rawInput: string) => rawInput.split("\n")
|
||||
.map((l) => Array.from(l.matchAll(/-?\d+/g)).map(Number))
|
||||
|
||||
const part1 = (rawInput: string) => {
|
||||
const input = parseInput(rawInput)
|
||||
const width = 101
|
||||
const height = 103
|
||||
let quadrantCounts = [0,0,0,0] // TL, TR, BR, BL
|
||||
const halfX = (width - 1) / 2
|
||||
const halfY = (height - 1) / 2
|
||||
input.forEach(([ix, iy, dx, dy]) => {
|
||||
const destx = (ix + (width + dx) * 100) % width
|
||||
const desty = (iy + (height + dy) * 100) % height
|
||||
if (desty === halfY || destx === halfX) { return }
|
||||
quadrantCounts[
|
||||
(desty > halfY ? 2 : 0) + (destx > halfX ? 1 : 0)
|
||||
] += 1
|
||||
})
|
||||
return quadrantCounts.reduce((total, here) => {
|
||||
return total * here
|
||||
}, 1)
|
||||
}
|
||||
|
||||
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')}`)
|
||||
}
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
run({
|
||||
part1: {
|
||||
tests: [
|
||||
// {
|
||||
// input: `p=0,4 v=3,-3
|
||||
// p=6,3 v=-1,-3
|
||||
// p=10,3 v=-1,2
|
||||
// p=2,0 v=2,-1
|
||||
// p=0,0 v=1,3
|
||||
// p=3,0 v=-2,-2
|
||||
// p=7,6 v=-1,-3
|
||||
// p=3,0 v=-1,-2
|
||||
// p=9,3 v=2,3
|
||||
// p=7,3 v=-1,2
|
||||
// p=2,4 v=2,-3
|
||||
// p=9,5 v=-3,-3`,
|
||||
// expected: 12,
|
||||
// },
|
||||
],
|
||||
solution: part1,
|
||||
},
|
||||
part2: {
|
||||
tests: [
|
||||
// {
|
||||
// input: ``,
|
||||
// expected: "",
|
||||
// },
|
||||
],
|
||||
solution: part2,
|
||||
},
|
||||
trimTestInputs: true,
|
||||
onlyTests: false,
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue