Compare commits
No commits in common. "95981a219af5fcf5ec52e6a9f47dc599221a8cf7" and "8b4120c53f5bcab9f94e6ed5c2fc62e94050a312" have entirely different histories.
95981a219a
...
8b4120c53f
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 89 KiB |
@ -1,6 +1,4 @@
|
|||||||
1:
|
1:
|
||||||
stars: 2
|
stars: 2
|
||||||
2:
|
2:
|
||||||
stars: 2
|
|
||||||
3:
|
|
||||||
stars: 2
|
stars: 2
|
@ -1 +0,0 @@
|
|||||||
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
|
|
@ -1 +0,0 @@
|
|||||||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
|
@ -1,16 +0,0 @@
|
|||||||
#import "/src/utils.typ": *
|
|
||||||
|
|
||||||
#let solve(input) = {
|
|
||||||
let matches = input.matches(regex("mul\((\d{1,3}),(\d{1,3})\)"))
|
|
||||||
let total = matches.map(m => {
|
|
||||||
m.captures.map(int)
|
|
||||||
.product()
|
|
||||||
}).sum()
|
|
||||||
return total
|
|
||||||
}
|
|
||||||
|
|
||||||
#show-puzzle(
|
|
||||||
3, 1,
|
|
||||||
solve,
|
|
||||||
example: ("1": 161)
|
|
||||||
)
|
|
@ -1,31 +0,0 @@
|
|||||||
#import "/src/utils.typ": *
|
|
||||||
|
|
||||||
#let solve(input) = {
|
|
||||||
let dos = input.matches(regex("do\(\)"))
|
|
||||||
let donts = input.matches(regex("don't\(\)"))
|
|
||||||
let toggles = dos.map(m => (m.end, true))
|
|
||||||
toggles += donts.map(m => (m.end, false))
|
|
||||||
toggles = toggles.sorted(key: t => t.first())
|
|
||||||
|
|
||||||
let is-enabled(i) = {
|
|
||||||
let t = toggles.rev().find(t => t.first() <= i)
|
|
||||||
return t == none or t.last()
|
|
||||||
}
|
|
||||||
|
|
||||||
let matches = input.matches(regex("mul\((\d{1,3}),(\d{1,3})\)"))
|
|
||||||
let total = matches.map(m => {
|
|
||||||
if is-enabled(m.start) {
|
|
||||||
m.captures.map(int)
|
|
||||||
.product()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}).sum()
|
|
||||||
return total
|
|
||||||
}
|
|
||||||
|
|
||||||
#show-puzzle(
|
|
||||||
3, 2,
|
|
||||||
solve,
|
|
||||||
example: ("2": 48)
|
|
||||||
)
|
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
@ -67,14 +67,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let show-puzzle(
|
#let show-puzzle(day, puzzle, func, example: none, visualize: none) = {
|
||||||
day,
|
|
||||||
puzzle,
|
|
||||||
func,
|
|
||||||
example: none,
|
|
||||||
visualize: none,
|
|
||||||
only-example: false
|
|
||||||
) = {
|
|
||||||
let check-example = check-example.with(visualize: visualize)
|
let check-example = check-example.with(visualize: visualize)
|
||||||
if example != none {
|
if example != none {
|
||||||
if type(example) == dictionary {
|
if type(example) == dictionary {
|
||||||
@ -87,11 +80,9 @@
|
|||||||
linebreak()
|
linebreak()
|
||||||
}
|
}
|
||||||
|
|
||||||
if not only-example {
|
let input = get-input(day)
|
||||||
let input = get-input(day)
|
let result = (func)(input)
|
||||||
let result = (func)(input)
|
show-result(result)
|
||||||
show-result(result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#let day-template(day, puzzle1, puzzle2, stars: 0) = {
|
#let day-template(day, puzzle1, puzzle2, stars: 0) = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user