added visualization for day 3 puzzle 1
This commit is contained in:
parent
0d89355f86
commit
da56d30760
@ -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
|
||||
)
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
Reference in New Issue
Block a user