day 14 puzzle 2

This commit is contained in:
Louis Heredero 2024-12-15 14:11:50 +01:00
parent 6ab8ef6d26
commit ab60a501f5
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
5 changed files with 43 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 123 KiB

View File

@ -25,4 +25,4 @@
13: 13:
stars: 2 stars: 2
14: 14:
stars: 1 stars: 2

View File

@ -6,11 +6,8 @@
return calc.rem-euclid(v0 + dv * steps, max) return calc.rem-euclid(v0 + dv * steps, max)
} }
#let solve(w: 0, h: 0, steps: 100, input) = { #let parse-input(input) = {
assert(w != 0, message: "Width must be != 0") return input.split("\n").map(b => {
assert(h != 0, message: "Height must be != 0")
let bots = input.split("\n").map(b => {
let m = b.match(regexp) let m = b.match(regexp)
return ( return (
pos: ( 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 = ( let quadrants = (
tl: 0, tl: 0,

View File

@ -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)

Binary file not shown.