diff --git a/progress.png b/progress.png index 78f6fd4..765b3a5 100644 Binary files a/progress.png and b/progress.png differ diff --git a/progress.yaml b/progress.yaml index 1be811c..c090e10 100644 --- a/progress.yaml +++ b/progress.yaml @@ -25,4 +25,4 @@ 13: stars: 2 14: - stars: 1 \ No newline at end of file + stars: 2 \ No newline at end of file diff --git a/src/day14/puzzle1.typ b/src/day14/puzzle1.typ index 7dc18bf..74c3563 100644 --- a/src/day14/puzzle1.typ +++ b/src/day14/puzzle1.typ @@ -6,11 +6,8 @@ return calc.rem-euclid(v0 + dv * steps, max) } -#let solve(w: 0, h: 0, steps: 100, input) = { - assert(w != 0, message: "Width must be != 0") - assert(h != 0, message: "Height must be != 0") - - let bots = input.split("\n").map(b => { +#let parse-input(input) = { + return input.split("\n").map(b => { let m = b.match(regexp) return ( pos: ( @@ -23,6 +20,13 @@ ) ) }) +} + +#let solve(w: 0, h: 0, steps: 100, input) = { + assert(w != 0, message: "Width must be != 0") + assert(h != 0, message: "Height must be != 0") + + let bots = parse-input(input) let quadrants = ( tl: 0, diff --git a/src/day14/puzzle2.typ b/src/day14/puzzle2.typ index e69de29..b7c528f 100644 --- a/src/day14/puzzle2.typ +++ b/src/day14/puzzle2.typ @@ -0,0 +1,33 @@ +#import "/src/utils.typ": * +#import "@preview/cetz:0.3.1": canvas, draw +#import "puzzle1.typ": parse-input, simulate + +#let input = get-input(14) +#let bots = parse-input(input) +#let res = 8270 +#let (width, height) = (101, 103) +#let sim-x = simulate.with(max: width, steps: res) +#let sim-y = simulate.with(max: height, steps: res) +#let size = 0.1 + +#figure( + canvas({ + draw.rect( + (0, 0), + (width * size, -height * size) + ) + for bot in bots { + let x = sim-x(bot.pos.x, bot.vel.x) + let y = sim-y(bot.pos.y, bot.vel.y) + draw.rect( + (x * size, -y * size), + ((x + 1) * size, -(y + 1) * size), + stroke: none, + fill: black + ) + } + }), + caption: "Christmas tree easter egg" +) + +#show-result(res) \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 6f65c38..357390c 100644 Binary files a/src/main.pdf and b/src/main.pdf differ