This commit is contained in:
dece 2021-12-06 12:50:27 +01:00
parent 65593392b2
commit 06eb7c1f08

35
2021/day6.py Normal file
View file

@ -0,0 +1,35 @@
import sys
def main():
lines = [line.rstrip() for line in sys.stdin]
data = {k: 0 for k in range(1, 6)}
for n in map(int, lines[0].split(",")):
data[n] += 1
# Part 1
for _ in range(80):
data = step(data)
print(sum(data.values()))
# Part 2
for _ in range(256 - 80):
data = step(data)
print(sum(data.values()))
def step(data):
next_data = {k: 0 for k in range(1, 9)}
for k, v in data.items():
if v == 0:
continue
if k == 0:
next_data[6] += v
next_data[8] += v
else:
next_data[k - 1] = v
return next_data
if __name__ == "__main__":
main()