day 7
This commit is contained in:
parent
e7bd950ce3
commit
6896c62cc8
11 changed files with 709 additions and 0 deletions
40
day_6/code.py
Normal file
40
day_6/code.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
db = False
|
||||
|
||||
import fileinput
|
||||
|
||||
state = []
|
||||
|
||||
lines = [l for l in fileinput.input()]
|
||||
assert(len(lines) > 0)
|
||||
assert(len(lines[0]) > 0)
|
||||
|
||||
rawState = list(map(int, lines[0].split(',')))
|
||||
|
||||
state = [0 for i in range(9)]
|
||||
|
||||
for s in rawState:
|
||||
state[s] += 1
|
||||
|
||||
days = 256
|
||||
day = 0
|
||||
|
||||
if db:
|
||||
print(day, ",".join(map(str, state)))
|
||||
|
||||
for day in range(1, days+1):
|
||||
nextState = [0 for i in range(9)]
|
||||
for i, s in enumerate(state):
|
||||
if i == 0:
|
||||
nextState[6] = s
|
||||
nextState[8] = s
|
||||
else:
|
||||
nextState[i-1] += s
|
||||
|
||||
state = nextState.copy()
|
||||
|
||||
if db:
|
||||
print(day, ",".join(map(str, state)))
|
||||
|
||||
print('===')
|
||||
print(sum(state))
|
||||
1
day_6/example.txt
Normal file
1
day_6/example.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
3,4,3,1,2
|
||||
2
day_6/input.txt
Normal file
2
day_6/input.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
2,1,1,1,1,1,1,5,1,1,1,1,5,1,1,3,5,1,1,3,1,1,3,1,4,4,4,5,1,1,1,3,1,3,1,1,2,2,1,1,1,5,1,1,1,5,2,5,1,1,2,1,3,3,5,1,1,4,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,4,1,5,1,2,1,1,1,1,5,1,1,1,1,1,5,1,1,1,4,5,1,1,3,4,1,1,1,3,5,1,1,1,2,1,1,4,1,4,1,2,1,1,2,1,5,1,1,1,5,1,2,2,1,1,1,5,1,2,3,1,1,1,5,3,2,1,1,3,1,1,3,1,3,1,1,1,5,1,1,1,1,1,1,1,3,1,1,1,1,3,1,1,4,1,1,3,2,1,2,1,1,2,2,1,2,1,1,1,4,1,2,4,1,1,4,4,1,1,1,1,1,4,1,1,1,2,1,1,2,1,5,1,1,1,1,1,5,1,3,1,1,2,3,4,4,1,1,1,3,2,4,4,1,1,3,5,1,1,1,1,4,1,1,1,1,1,5,3,1,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,5,1,4,4,1,1,1,1,1,1,1,1,3,1,3,1,4,1,1,2,2,2,1,1,2,1,1
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue