day 22 puzzle 1
This commit is contained in:
parent
47fbeb1ce9
commit
056e29b96c
26
day22.py
Normal file
26
day22.py
Normal file
@ -0,0 +1,26 @@
|
||||
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 |
@ -39,4 +39,6 @@
|
||||
20:
|
||||
stars: 1
|
||||
21:
|
||||
stars: 0
|
||||
stars: 0
|
||||
22:
|
||||
stars: 1
|
1
res/examples/day22.txt
Normal file
1
res/examples/day22.txt
Normal file
@ -0,0 +1 @@
|
||||
123
|
61
src/day22/puzzle1.typ
Normal file
61
src/day22/puzzle1.typ
Normal file
@ -0,0 +1,61 @@
|
||||
#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
|
0
src/day22/puzzle2.typ
Normal file
0
src/day22/puzzle2.typ
Normal file
BIN
src/main.pdf
BIN
src/main.pdf
Binary file not shown.
Loading…
Reference in New Issue
Block a user