Compare commits
No commits in common. "1f0389071c383698cd35736f446e6fa94b664d95" and "0d89355f867182a7a28f5cb8f56cb0e7ffc2ba97" have entirely different histories.
1f0389071c
...
0d89355f86
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 113 KiB |
@ -11,6 +11,4 @@
|
|||||||
6:
|
6:
|
||||||
stars: 2
|
stars: 2
|
||||||
7:
|
7:
|
||||||
stars: 2
|
stars: 2
|
||||||
8:
|
|
||||||
stars: 1
|
|
@ -1,12 +0,0 @@
|
|||||||
............
|
|
||||||
........0...
|
|
||||||
.....0......
|
|
||||||
.......0....
|
|
||||||
....0.......
|
|
||||||
......A.....
|
|
||||||
............
|
|
||||||
............
|
|
||||||
........A...
|
|
||||||
.........A..
|
|
||||||
............
|
|
||||||
............
|
|
@ -1,8 +1,7 @@
|
|||||||
#import "/src/utils.typ": *
|
#import "/src/utils.typ": *
|
||||||
|
|
||||||
#let reg = regex("mul\((\d{1,3}),(\d{1,3})\)")
|
|
||||||
#let solve(input) = {
|
#let solve(input) = {
|
||||||
let matches = input.matches(reg)
|
let matches = input.matches(regex("mul\((\d{1,3}),(\d{1,3})\)"))
|
||||||
let total = matches.map(m => {
|
let total = matches.map(m => {
|
||||||
m.captures.map(int)
|
m.captures.map(int)
|
||||||
.product()
|
.product()
|
||||||
@ -10,24 +9,8 @@
|
|||||||
return total
|
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(
|
#show-puzzle(
|
||||||
3, 1,
|
3, 1,
|
||||||
solve,
|
solve,
|
||||||
example: ("1": 161),
|
example: ("1": 161)
|
||||||
visualize: visualize
|
|
||||||
)
|
)
|
@ -1,5 +1,4 @@
|
|||||||
#import "/src/utils.typ": *
|
#import "/src/utils.typ": *
|
||||||
#import "@preview/cetz:0.3.1": canvas, draw
|
|
||||||
|
|
||||||
#let make-rules-dict(rules) = {
|
#let make-rules-dict(rules) = {
|
||||||
let dict = (:)
|
let dict = (:)
|
||||||
@ -46,82 +45,8 @@
|
|||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
#let visualize(input) = {
|
|
||||||
let (rules, updates) = input.split("\n\n")
|
|
||||||
rules = rules.split("\n").map(l => l.split("|").map(int))
|
|
||||||
updates = updates.split("\n").map(l => l.split(",").map(int))
|
|
||||||
|
|
||||||
let total = 0
|
|
||||||
//let rules-dict = make-rules-dict(rules)
|
|
||||||
|
|
||||||
let diags = ()
|
|
||||||
for update in updates {
|
|
||||||
let diag = canvas(length: 3em, {
|
|
||||||
for (x, n) in update.enumerate() {
|
|
||||||
draw.circle(
|
|
||||||
(x, 0),
|
|
||||||
radius: 0.4,
|
|
||||||
name: str(x)
|
|
||||||
)
|
|
||||||
draw.content(
|
|
||||||
(x, 0),
|
|
||||||
str(n)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
let flip = false
|
|
||||||
let c = 1
|
|
||||||
for (a, b) in rules {
|
|
||||||
let i = update.position(n => n == a)
|
|
||||||
let j = update.position(n => n == b)
|
|
||||||
if i == none or j == none {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
let anchor = if flip {".south"} else {".north"}
|
|
||||||
let pt-i = str(i) + anchor
|
|
||||||
let pt-j = str(j) + anchor
|
|
||||||
let col = if j < i {red} else {green}
|
|
||||||
|
|
||||||
draw.arc-through(
|
|
||||||
pt-i,
|
|
||||||
(
|
|
||||||
rel: (0, if flip {-c / 10} else {c / 10}),
|
|
||||||
to: (pt-i, 50%, pt-j)
|
|
||||||
),
|
|
||||||
pt-j,
|
|
||||||
mark: (end: ">", fill: col),
|
|
||||||
stroke: col
|
|
||||||
)
|
|
||||||
|
|
||||||
flip = not flip
|
|
||||||
c += 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
diags.push(diag)
|
|
||||||
|
|
||||||
/*if is-update-valid(rules-dict, update) {
|
|
||||||
total += update.at(calc.div-euclid(update.len(), 2))
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
diags.last() = grid.cell(
|
|
||||||
colspan: 2 - calc.rem(diags.len() - 1, 2),
|
|
||||||
diags.last()
|
|
||||||
)
|
|
||||||
|
|
||||||
grid(
|
|
||||||
columns: 2,
|
|
||||||
stroke: (paint: black, dash: "dashed"),
|
|
||||||
align: center + horizon,
|
|
||||||
inset: 0.4em,
|
|
||||||
..diags
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#show-puzzle(
|
#show-puzzle(
|
||||||
5, 1,
|
5, 1,
|
||||||
solve,
|
solve,
|
||||||
example: 143,
|
example: 143
|
||||||
visualize: visualize
|
|
||||||
)
|
)
|
@ -1,51 +0,0 @@
|
|||||||
#import "/src/utils.typ": *
|
|
||||||
|
|
||||||
#let in-grid(w, h, x, y) = {
|
|
||||||
return 0 <= x and x < w and 0 <= y and y < h
|
|
||||||
}
|
|
||||||
|
|
||||||
#let solve(input) = {
|
|
||||||
let by-freq = (:)
|
|
||||||
let antinodes = ()
|
|
||||||
|
|
||||||
let grid = input.split("\n").map(l => l.clusters())
|
|
||||||
let w = grid.first().len()
|
|
||||||
let h = grid.len()
|
|
||||||
|
|
||||||
let in-grid = in-grid.with(w, h)
|
|
||||||
|
|
||||||
for y in range(h) {
|
|
||||||
for x in range(w) {
|
|
||||||
let c = grid.at(y).at(x)
|
|
||||||
if c == "." {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if c not in by-freq {
|
|
||||||
by-freq.insert(c, ())
|
|
||||||
}
|
|
||||||
|
|
||||||
for (x2, y2) in by-freq.at(c) {
|
|
||||||
let (dx, dy) = (x2 - x, y2 - y)
|
|
||||||
let node1 = (x - dx, y - dy)
|
|
||||||
let node2 = (x2 + dx, y2 + dy)
|
|
||||||
|
|
||||||
if in-grid(..node1) and node1 not in antinodes {
|
|
||||||
antinodes.push(node1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if in-grid(..node2) and node2 not in antinodes {
|
|
||||||
antinodes.push(node2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
by-freq.at(c).push((x, y))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return antinodes.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
#show-puzzle(
|
|
||||||
8, 1,
|
|
||||||
solve,
|
|
||||||
example: 14
|
|
||||||
)
|
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user