diff --git a/src/day3/puzzle1.typ b/src/day3/puzzle1.typ index d4a520d..7156363 100644 --- a/src/day3/puzzle1.typ +++ b/src/day3/puzzle1.typ @@ -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 ) \ No newline at end of file diff --git a/src/main.pdf b/src/main.pdf index 98dc970..5c95bab 100644 Binary files a/src/main.pdf and b/src/main.pdf differ