2016: d16: ex1: add solution
This commit is contained in:
parent
16d54ff2e0
commit
13740c7423
1 changed files with 30 additions and 0 deletions
30
2016/d16/ex1/ex1.py
Executable file
30
2016/d16/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> str:
|
||||||
|
def curve_step(input: str) -> str:
|
||||||
|
b = input.translate(str.maketrans("01", "10"))[::-1]
|
||||||
|
return input + "0" + b
|
||||||
|
|
||||||
|
def checksum(state: str) -> str:
|
||||||
|
while len(state) % 2 == 0:
|
||||||
|
state = "".join(str(int(a == b)) for a, b in itertools.batched(state, 2))
|
||||||
|
return state
|
||||||
|
|
||||||
|
state = input.strip()
|
||||||
|
disk_size = 272
|
||||||
|
while len(state) < disk_size:
|
||||||
|
state = curve_step(state)
|
||||||
|
return checksum(state[:disk_size])
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue