Compare commits
No commits in common. "056e29b96c9ad2dfa71894297862c5d9f65d94ef" and "4826c0d21e43713efc149c48ea8c506107f1558c" have entirely different histories.
056e29b96c
...
4826c0d21e
26
day22.py
26
day22.py
@ -1,26 +0,0 @@
|
|||||||
with open("res/inputs/day22.txt", "r") as f:
|
|
||||||
values = list(map(int, f.read().split("\n")))
|
|
||||||
|
|
||||||
calls = 0
|
|
||||||
|
|
||||||
def step(a, shift):
|
|
||||||
global calls
|
|
||||||
calls += 1
|
|
||||||
s = (a >> -shift) if shift < 0 else (a << shift)
|
|
||||||
return (s ^ a) & 0xffffff
|
|
||||||
|
|
||||||
def rand(value):
|
|
||||||
b = step(value, 6)
|
|
||||||
c = step(b, -5)
|
|
||||||
d = step(c, 11)
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
total = 0
|
|
||||||
for v in values:
|
|
||||||
for _ in range(2000):
|
|
||||||
v = rand(v)
|
|
||||||
total += v
|
|
||||||
|
|
||||||
print(total)
|
|
||||||
print(calls)
|
|
BIN
progress.png
BIN
progress.png
Binary file not shown.
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
@ -37,8 +37,4 @@
|
|||||||
19:
|
19:
|
||||||
stars: 2
|
stars: 2
|
||||||
20:
|
20:
|
||||||
stars: 1
|
|
||||||
21:
|
|
||||||
stars: 0
|
|
||||||
22:
|
|
||||||
stars: 1
|
stars: 1
|
@ -1,5 +0,0 @@
|
|||||||
029A
|
|
||||||
980A
|
|
||||||
179A
|
|
||||||
456A
|
|
||||||
379A
|
|
@ -1 +0,0 @@
|
|||||||
123
|
|
@ -1,100 +0,0 @@
|
|||||||
#import "/src/utils.typ": *
|
|
||||||
|
|
||||||
#let nums = (
|
|
||||||
"7": (0, 0),
|
|
||||||
"8": (1, 0),
|
|
||||||
"9": (2, 0),
|
|
||||||
"4": (0, 1),
|
|
||||||
"5": (1, 1),
|
|
||||||
"6": (2, 1),
|
|
||||||
"1": (0, 2),
|
|
||||||
"2": (1, 2),
|
|
||||||
"3": (2, 2),
|
|
||||||
"0": (1, 3),
|
|
||||||
"A": (2, 3),
|
|
||||||
)
|
|
||||||
|
|
||||||
#let arrows = (
|
|
||||||
"^": (1, 0),
|
|
||||||
"A": (2, 0),
|
|
||||||
"<": (0, 1),
|
|
||||||
"v": (1, 1),
|
|
||||||
">": (2, 1),
|
|
||||||
)
|
|
||||||
|
|
||||||
#let get-num-path(code) = {
|
|
||||||
let path = ""
|
|
||||||
let (x, y) = nums.at("A")
|
|
||||||
for char in code {
|
|
||||||
let (x2, y2) = nums.at(char)
|
|
||||||
let dy = y2 - y
|
|
||||||
let dx = x2 - x
|
|
||||||
let ver = if dy == 0 {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
(if dy < 0 {"^"} else {"v"}) * calc.abs(dy)
|
|
||||||
}
|
|
||||||
let hor = if dx == 0 {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
(if dx < 0 {"<"} else {">"}) * calc.abs(dx)
|
|
||||||
}
|
|
||||||
path += if y == 3 and x2 == 0 {
|
|
||||||
ver + hor
|
|
||||||
} else {
|
|
||||||
hor + ver
|
|
||||||
} + "A"
|
|
||||||
(x, y) = (x2, y2)
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
#let get-dir-path(code) = {
|
|
||||||
let path = ""
|
|
||||||
let (x, y) = arrows.at("A")
|
|
||||||
for char in code {
|
|
||||||
let (x2, y2) = arrows.at(char)
|
|
||||||
let dy = y2 - y
|
|
||||||
let dx = x2 - x
|
|
||||||
let ver = if dy == 0 {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
(if dy < 0 {"^"} else {"v"}) * calc.abs(dy)
|
|
||||||
}
|
|
||||||
let hor = if dx == 0 {
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
(if dx < 0 {"<"} else {">"}) * calc.abs(dx)
|
|
||||||
}
|
|
||||||
path += if x == 0 and dy < 0 {
|
|
||||||
hor + ver
|
|
||||||
} else {
|
|
||||||
ver + hor
|
|
||||||
} + "A"
|
|
||||||
(x, y) = (x2, y2)
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
#let get-path(code) = {
|
|
||||||
let num-path = get-num-path(code)
|
|
||||||
let dir-path-1 = get-dir-path(num-path)
|
|
||||||
let dir-path-2 = get-dir-path(dir-path-1)
|
|
||||||
return dir-path-2
|
|
||||||
}
|
|
||||||
|
|
||||||
#let solve(input) = {
|
|
||||||
let codes = input.split("\n")
|
|
||||||
let total = 0
|
|
||||||
for code in codes {
|
|
||||||
let len = get-path(code).len()
|
|
||||||
let num = int(code.slice(0, code.len() - 1))
|
|
||||||
total += len * num
|
|
||||||
}
|
|
||||||
return total
|
|
||||||
}
|
|
||||||
#show-puzzle(
|
|
||||||
21, 1,
|
|
||||||
solve,
|
|
||||||
example: 126384
|
|
||||||
)
|
|
@ -1,61 +0,0 @@
|
|||||||
#import "/src/utils.typ": *
|
|
||||||
|
|
||||||
#let random(prev) = {
|
|
||||||
let step(a, shift) = {
|
|
||||||
let s = if shift < 0 {
|
|
||||||
a.bit-rshift(-shift)
|
|
||||||
} else {
|
|
||||||
a.bit-lshift(shift)
|
|
||||||
}
|
|
||||||
return s.bit-xor(a).bit-and(0xffffff)
|
|
||||||
}
|
|
||||||
let b = step(prev, 6)
|
|
||||||
let c = step(b, -5)
|
|
||||||
let d = step(c, 11)
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
#let solve(input, steps: 1) = {
|
|
||||||
let values = input.split("\n").map(int)
|
|
||||||
let total = 0
|
|
||||||
for value in values {
|
|
||||||
for _ in range(steps) {
|
|
||||||
value = random(value)
|
|
||||||
}
|
|
||||||
total += value
|
|
||||||
}
|
|
||||||
return total
|
|
||||||
}
|
|
||||||
|
|
||||||
#let examples = ()
|
|
||||||
#let results = (
|
|
||||||
15887950,
|
|
||||||
16495136,
|
|
||||||
527345,
|
|
||||||
704524,
|
|
||||||
1553684,
|
|
||||||
12683156,
|
|
||||||
11100544,
|
|
||||||
12249484,
|
|
||||||
7753432,
|
|
||||||
5908254
|
|
||||||
)
|
|
||||||
#for (i, res) in results.enumerate() {
|
|
||||||
examples.push((
|
|
||||||
result: res,
|
|
||||||
args: (steps: i + 1)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#show-puzzle(
|
|
||||||
22, 1,
|
|
||||||
solve.with(steps: 2000),
|
|
||||||
example: examples,
|
|
||||||
only-example: true
|
|
||||||
)
|
|
||||||
|
|
||||||
#show-result(18261820068)
|
|
||||||
|
|
||||||
//B = ((A << 6) ^ A) & 0xffffff\
|
|
||||||
//C = ((B >> 5) ^ B) & 0xffffff\
|
|
||||||
//D = ((C << 11) ^ C) & 0xffffff
|
|
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user