Solve 2016:16 p1-2 "Dragon Checksum"
This commit is contained in:
parent
623253ac9d
commit
cdd5f63be4
2 changed files with 43 additions and 11 deletions
|
|
@ -142,16 +142,6 @@ def M(s, e):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use dummy data
|
|
||||||
inp = """
|
|
||||||
The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip.
|
|
||||||
The second floor contains a hydrogen generator.
|
|
||||||
The third floor contains a lithium generator.
|
|
||||||
The fourth floor contains nothing relevant.
|
|
||||||
""".strip()
|
|
||||||
|
|
||||||
z, _ = solve(inp)
|
|
||||||
|
|
||||||
with open("./input/11.txt", "r") as f:
|
with open("./input/11.txt", "r") as f:
|
||||||
inp = f.read().strip()
|
inp = f.read().strip()
|
||||||
|
|
||||||
|
|
@ -160,6 +150,5 @@ if __name__ == "__main__":
|
||||||
a = part_1(inp)
|
a = part_1(inp)
|
||||||
b = part_2(inp)
|
b = part_2(inp)
|
||||||
|
|
||||||
assert z == 11
|
|
||||||
assert a == 37
|
assert a == 37
|
||||||
assert b == 61
|
assert b == 61
|
||||||
|
|
|
||||||
43
2016-python2/output/day_16.py
Normal file
43
2016-python2/output/day_16.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
from output import answer # , matrix, D, DD, ADJ, ints, mhd, mdbg, vdbg
|
||||||
|
|
||||||
|
n = 16
|
||||||
|
title = "Dragon Checksum"
|
||||||
|
|
||||||
|
|
||||||
|
@answer(1, "The checksum to the state to fill first disc is {}")
|
||||||
|
def part_1(presolved):
|
||||||
|
return presolved[0]
|
||||||
|
|
||||||
|
|
||||||
|
@answer(2, "The checksum to the state to fill second disc is {}")
|
||||||
|
def part_2(presolved):
|
||||||
|
return presolved[1]
|
||||||
|
|
||||||
|
|
||||||
|
def solve(data):
|
||||||
|
p12 = []
|
||||||
|
for DS in [272, 35651584]:
|
||||||
|
s = [int(c) for c in data]
|
||||||
|
while len(s) < DS:
|
||||||
|
b = [abs(int(c) - 1) for c in s[::-1]]
|
||||||
|
s = s + [0] + b
|
||||||
|
s = s[:DS]
|
||||||
|
p = len(s)
|
||||||
|
while p % 2 == 0:
|
||||||
|
s = [int(a == b) for a, b in zip(s[::2], s[1::2])]
|
||||||
|
p = len(s)
|
||||||
|
p12.append("".join(map(str, s)))
|
||||||
|
return p12
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
with open("./input/16.txt", "r") as f:
|
||||||
|
inp = f.read().strip()
|
||||||
|
|
||||||
|
inp = solve(inp)
|
||||||
|
|
||||||
|
a = part_1(inp)
|
||||||
|
b = part_2(inp)
|
||||||
|
|
||||||
|
assert a == "10011010010010010"
|
||||||
|
assert b == "10101011110100011"
|
||||||
Loading…
Add table
Reference in a new issue