Compare commits

..

No commits in common. "7a8faae694916f056c5448eea66d9df31d9c8d5b" and "f77a97fd80266ac8b0b2b3d0699bcaa1e2848813" have entirely different histories.

9 changed files with 13 additions and 128 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 86 KiB

View File

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

View File

@ -1,6 +0,0 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9

View File

@ -15,7 +15,7 @@
}
#show-puzzle(
1, 1,
1,
solve,
example: 11
)

View File

@ -1,5 +1,4 @@
#import "/src/utils.typ": *
#import "@preview/cetz:0.3.1": canvas, draw
#let solve(input) = {
let lines = input.split("\n")
@ -30,57 +29,8 @@
return total
}
#let visualize(input) = {
let lines = input.split("\n")
let (l1, l2) = ((), ())
let reg = regex("^(\d+)\s+(\d+)$")
for line in lines {
let digits = line.match(reg)
l1.push(digits.captures.first())
l2.push(digits.captures.last())
}
let unique = l1.dedup()
let colors = (red,green)
canvas({
for (i, n) in l1.enumerate() {
let y = -0.9 * i
draw.circle(
(0, y),
radius: 0.35,
stroke: black,
name: "l" + str(i)
)
draw.content((0, y), n)
}
for (i, n) in l2.enumerate() {
let y = -0.9 * i
draw.circle(
(4, y),
radius: 0.35,
stroke: black,
name: "r" + str(i)
)
draw.content((4, y), n)
}
for (i, a) in l1.enumerate() {
for (j, b) in l2.enumerate() {
if a == b {
draw.line(
"l" + str(i),
"r" + str(j),
stroke: colors.at(unique.position(n => n == a)) + 1.5pt,
mark: (end: "straight")
)
}
}
}
})
}
#show-puzzle(
1, 2,
1,
solve,
example: 31,
visualize: visualize
example: 31
)

View File

@ -1,35 +0,0 @@
#import "/src/utils.typ": *
#let solve(input) = {
let safe-cnt = 0
for line in input.split("\n") {
let nums = line.split(" ").map(n => int(n))
let increasing
let safe = true
for i in range(nums.len() - 1) {
let d = nums.at(i + 1) - nums.at(i)
let abs-d = calc.abs(d)
if abs-d < 1 or abs-d > 3 {
safe = false
break
}
if i == 0 {
increasing = d > 0
} else if (d > 0) != increasing {
safe = false
break
}
}
if safe {
safe-cnt += 1
}
}
return safe-cnt
}
#show-puzzle(
2, 1,
solve,
example: 2
)

View File

Binary file not shown.

View File

@ -1,7 +1,5 @@
#let star-state = state("stars", (:))
#let star = text(font: "Twitter Color Emoji", emoji.star)
#let get-input-path(day) = {
return "/res/inputs/day" + str(day) + ".txt"
}
@ -15,15 +13,8 @@
return read(get-input-path(day))
}
#let check-example(
day,
func,
target-result,
suffix: none,
visualize: none
) = {
let input = read(get-example-path(day, suffix: suffix))
let result = (func)(input)
#let check-example(day, func, target-result, suffix: none) = {
let result = (func)(read(get-example-path(day, suffix: suffix)))
let passes = (result == target-result)
let name = if suffix == none [Example] else [Example '#suffix']
let badge = box(
@ -47,14 +38,6 @@
}
[#badge #h(0.6em)]
if visualize != none {
linebreak()
figure(
visualize(input),
caption: [#name (visualization)]
)
}
}
#let show-result(result) = {
@ -63,35 +46,30 @@
radius: 1.2em,
baseline: 35%,
fill: blue.lighten(20%),
text(fill: white)[Result: #raw(repr(result))]
text(fill: white)[Result: #result]
)
}
#let show-puzzle(day, puzzle, func, example: none, visualize: none) = {
let check-example = check-example.with(visualize: visualize)
#let show-puzzle(puzzle, func, example: none) = {
if example != none {
if type(example) == dictionary {
for (suffix, result) in example.pairs() {
check-example(day, func, result, suffix: suffix)
check-example(puzzle, func, result, suffix: suffix)
}
} else {
check-example(day, func, example)
check-example(puzzle, func, example)
}
linebreak()
}
let input = get-input(day)
let input = get-input(1)
let result = (func)(input)
show-result(result)
}
#let day-template(day, puzzle1, puzzle2, stars: 0) = {
pagebreak(weak: true)
let title = [Day #day] + box(
baseline: -1pt,
((star,)*stars).join()
)
let title = [Day #day] + ((emoji.star,)*stars).join()
[
= #title
#label("day-" + str(day))
@ -130,7 +108,7 @@
dir: ttb,
spacing: 0.2em,
cell,
((star,)* stars.at(str(i))).join()
h(3pt) + ((emoji.star,)* stars.at(str(i))).join()
)
if links {
cell = link(label("day-" + str(i)), cell)