added visualization for day 3 puzzle 1

This commit is contained in:
Louis Heredero 2024-12-08 02:10:50 +01:00
parent 0d89355f86
commit da56d30760
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 19 additions and 2 deletions

View File

@ -1,7 +1,8 @@
#import "/src/utils.typ": *
#let reg = regex("mul\((\d{1,3}),(\d{1,3})\)")
#let solve(input) = {
let matches = input.matches(regex("mul\((\d{1,3}),(\d{1,3})\)"))
let matches = input.matches(reg)
let total = matches.map(m => {
m.captures.map(int)
.product()
@ -9,8 +10,24 @@
return total
}
#let visualize(input) = {
[
#set text(size: 1.2em)
#show reg: it => {
let m = it.text.match(reg)
let v = m.captures.map(int).product()
math.underbrace(
highlight(fill: red, raw(it.text)),
text(size: 1.5em, str(v))
)
}
#raw(input)
]
}
#show-puzzle(
3, 1,
solve,
example: ("1": 161)
example: ("1": 161),
visualize: visualize
)

Binary file not shown.