No need for dictionnary, simple list index is enough

This commit is contained in:
kleph 2021-12-07 11:30:00 +01:00
parent 7db14d6368
commit 992124623b

View file

@ -7,7 +7,7 @@ def parse_file(file):
list_state = [int(x) for x in line.split(',')] list_state = [int(x) for x in line.split(',')]
state = dict(zip(range(0, 9), [0]*9)) state = [0] * 9
for c in range(0, 9): for c in range(0, 9):
state[c] = list_state.count(c) state[c] = list_state.count(c)
@ -36,8 +36,4 @@ DAYS = 256
for d in range(DAYS): for d in range(DAYS):
iterate(init_state) iterate(init_state)
lanternfish = 0 print(f'There\'s {sum(init_state)} lanternfish after {DAYS} days')
for k, v in init_state.items():
lanternfish += v
print(f'There\'s {lanternfish} lanternfish after {DAYS} days')