Compare commits

..

No commits in common. "11277f06775b11d920613905a17b3d0a1b395803" and "7bcab0b085b705d9d77180f5fda28feeb1e858f9" have entirely different histories.

3 changed files with 6 additions and 95 deletions

View File

@ -1,11 +1,10 @@
#import "/src/utils.typ": *
#import "@preview/cetz:0.3.1": canvas, draw
#let check-xmas(lines, ox, oy) = {
let w = lines.first().len()
let h = lines.len()
let dirs = ()
let total = 0
for dy in (-1, 0, 1) {
for dx in (-1, 0, 1) {
if dx == 0 and dy == 0 {
@ -27,11 +26,11 @@
}
}
if buffer == "XMAS" {
dirs.push((dx, dy))
total += 1
}
}
}
return dirs
return total
}
#let solve(input) = {
@ -43,7 +42,7 @@
for y in range(h) {
for x in range(w) {
if lines.at(y).at(x) == "X" {
total += check-xmas(lines, x, y).len()
total += check-xmas(lines, x, y)
}
}
}
@ -51,41 +50,8 @@
return total
}
#let visualize(input) = {
let lines = input.split("\n")
let w = lines.first().len()
let h = lines.len()
canvas({
for y in range(h) {
for x in range(w) {
if lines.at(y).at(x) == "X" {
let key = str(x) + "-" + str(y)
let dirs = check-xmas(lines, x, y)
draw.on-layer(2, {
for (dx, dy) in dirs {
draw.line(
(x + dx * 0.2, y + dy * 0.2),
(x + dx * 2.8, y + dy * 2.8),
stroke: red,
fill: red,
mark: (end: ">")
)
}
})
}
draw.content(
(x, y),
lines.at(y).at(x)
)
}
}
})
}
#show-puzzle(
4, 1,
solve,
example: 18,
visualize: visualize
example: 18
)

View File

@ -1,5 +1,4 @@
#import "/src/utils.typ": *
#import "@preview/cetz:0.3.1": canvas, draw
#let solve(input) = {
let lines = input.split("\n")
@ -27,62 +26,8 @@
return total
}
#let visualize(input) = {
let lines = input.split("\n")
let w = lines.first().len()
let h = lines.len()
let perms = (("M", "S"), ("S", "M"))
let positions = ()
for y in range(1, h - 1) {
for x in range(1, w - 1) {
if lines.at(y).at(x) == "A" {
let tl = lines.at(y - 1).at(x - 1)
let tr = lines.at(y - 1).at(x + 1)
let bl = lines.at(y + 1).at(x - 1)
let br = lines.at(y + 1).at(x + 1)
let tlbr = (tl, br)
let bltr = (bl, tr)
if tlbr in perms and bltr in perms {
positions.push((x, y))
}
}
}
}
canvas({
for y in range(h) {
for x in range(w) {
let valid = (x, y) in positions
if valid {
draw.circle(
(x, y),
radius: 0.3,
stroke: red,
name: str(x) + "-" + str(y)
)
for dy in (-1, 1) {
for dx in (-1, 1) {
draw.line(
str(x) + "-" + str(y),
(x + dx * 0.75, y + dy * 0.75),
stroke: red
)
}
}
}
draw.content(
(x, y),
lines.at(y).at(x)
)
}
}
})
}
#show-puzzle(
4, 2,
solve,
example: 9,
visualize: visualize
example: 9
)

Binary file not shown.