day 4 puzzle 2

This commit is contained in:
Louis Heredero 2024-12-04 09:49:16 +01:00
parent 65beed1c51
commit 7bcab0b085
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
5 changed files with 35 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 110 KiB

View File

@ -5,4 +5,4 @@
3:
stars: 2
4:
stars: 1
stars: 2

View File

@ -40,7 +40,7 @@
let total = 0
for y in range(h) {
for x in range(h) {
for x in range(w) {
if lines.at(y).at(x) == "X" {
total += check-xmas(lines, x, y)
}

View File

@ -0,0 +1,33 @@
#import "/src/utils.typ": *
#let solve(input) = {
let lines = input.split("\n")
let w = lines.first().len()
let h = lines.len()
let perms = (("M", "S"), ("S", "M"))
let total = 0
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 {
total += 1
}
}
}
}
return total
}
#show-puzzle(
4, 2,
solve,
example: 9
)

Binary file not shown.