Added 2021 (python)
This commit is contained in:
1
2021/06/input
Normal file
1
2021/06/input
Normal file
@ -0,0 +1 @@
|
||||
1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1
|
35
2021/06/prog.py
Normal file
35
2021/06/prog.py
Normal file
@ -0,0 +1,35 @@
|
||||
VERBOSE = True
|
||||
def verbose(s = "", *args, **kwargs):
|
||||
if VERBOSE:
|
||||
print(s, *args, **kwargs)
|
||||
|
||||
def get_input(sample = False, part = 1):
|
||||
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
|
||||
return list(map(lambda x: int(x), f.readlines()[0].split(',')))
|
||||
|
||||
|
||||
def create_state(l):
|
||||
return [0 for _ in range(l)]
|
||||
|
||||
def result(inp, days = 80):
|
||||
state = create_state(9)
|
||||
for n in inp:
|
||||
state[n] += 1
|
||||
|
||||
for _ in range(days):
|
||||
zeros = state[0]
|
||||
for i, n in enumerate( state[1:] ):
|
||||
state[i] = n
|
||||
state[6] += zeros
|
||||
state[8] = zeros
|
||||
|
||||
res = 0
|
||||
for n in state:
|
||||
res += n
|
||||
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
VERBOSE = False
|
||||
print(result(get_input(), days = 256))
|
1
2021/06/sample_p1
Normal file
1
2021/06/sample_p1
Normal file
@ -0,0 +1 @@
|
||||
3,4,3,1,2
|
11
2021/06/test.py
Normal file
11
2021/06/test.py
Normal file
@ -0,0 +1,11 @@
|
||||
from prog import *
|
||||
import unittest
|
||||
|
||||
class Tests(unittest.TestCase):
|
||||
def test_part1(self):
|
||||
self.assertEqual(result(get_input(sample = True), days = 18), 26)
|
||||
self.assertEqual(result(get_input(sample = True)), 5934)
|
||||
|
||||
def test_part2(self):
|
||||
self.assertEqual(result(get_input(sample = True), days = 256), 26984457539)
|
||||
|
Reference in New Issue
Block a user