d10
This commit is contained in:
parent
cf13c83a63
commit
dfb8e09ec9
60
day10.py
Normal file
60
day10.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def cycle(sequence: list, sizes: list, index: int = 0, skip_length: int = 0) -> (list, int, int):
|
||||||
|
for size in sizes:
|
||||||
|
for inc in range(size // 2):
|
||||||
|
l, r = (index + inc) % 256, (index + size - inc - 1) % 256
|
||||||
|
sequence[l], sequence[r] = sequence[r], sequence[l]
|
||||||
|
index = (index + size + skip_length) % 256
|
||||||
|
skip_length += 1
|
||||||
|
|
||||||
|
return sequence, index, skip_length
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(62238, "input10")
|
||||||
|
],
|
||||||
|
[
|
||||||
|
("2b0c9cc0449507a0db3babd57ad9e8d8", "input10")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
sizes = self.getInputAsArraySplit(",", int)
|
||||||
|
sequence, _, _ = cycle(list(range(256)), sizes)
|
||||||
|
return sequence[0] * sequence[1]
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
sizes = []
|
||||||
|
for x in self.getInput().strip():
|
||||||
|
sizes.append(ord(x))
|
||||||
|
sizes += [17, 31, 73, 47, 23]
|
||||||
|
index = 0
|
||||||
|
skip_length = 0
|
||||||
|
sequence = list(range(256))
|
||||||
|
|
||||||
|
for i in range(64):
|
||||||
|
sequence, index, skip_length = cycle(sequence, sizes, index, skip_length)
|
||||||
|
|
||||||
|
dense = []
|
||||||
|
for m in range(16):
|
||||||
|
xor = 0
|
||||||
|
for i in range(16):
|
||||||
|
xor ^= sequence[m * 16 + i]
|
||||||
|
|
||||||
|
dense.append(xor)
|
||||||
|
|
||||||
|
hex_string = ""
|
||||||
|
for v in dense:
|
||||||
|
hex_string += ("%x" % v).rjust(2, '0')
|
||||||
|
|
||||||
|
return hex_string
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
day = Day(2017, 10)
|
||||||
|
day.run(verbose=True)
|
||||||
1
inputs/input10
Normal file
1
inputs/input10
Normal file
@ -0,0 +1 @@
|
|||||||
|
157,222,1,2,177,254,0,228,159,140,249,187,255,51,76,30
|
||||||
Loading…
Reference in New Issue
Block a user