day 6
This commit is contained in:
parent
46450b9c2f
commit
9f5ce69cf7
26
day6/day6.py
Normal file
26
day6/day6.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
from collections import defaultdict, Counter
|
||||||
|
|
||||||
|
def calculate_fishes(inp, days):
|
||||||
|
fishes = Counter(inp)
|
||||||
|
for day in range(days):
|
||||||
|
fishes_new = defaultdict(int)
|
||||||
|
for fish, cnt in fishes.items():
|
||||||
|
if fish == 0:
|
||||||
|
fishes_new[8] += cnt
|
||||||
|
fishes_new[6] += cnt
|
||||||
|
else:
|
||||||
|
fishes_new[fish - 1] += cnt
|
||||||
|
fishes = fishes_new
|
||||||
|
return sum(fishes.values())
|
||||||
|
|
||||||
|
|
||||||
|
def main(infile):
|
||||||
|
with open(infile) as f:
|
||||||
|
inp = [int(x) for x in f.readline().split(",")]
|
||||||
|
res = calculate_fishes(inp, 80)
|
||||||
|
print(f"Part 1, {res}")
|
||||||
|
res = calculate_fishes(inp, 256)
|
||||||
|
print(f"Part 2, {res}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main("input.txt")
|
34
day6/day6_2.py
Normal file
34
day6/day6_2.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
total = 0
|
||||||
|
numbers = [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
|
data = [int(x) for x in f.readline().split(',')]
|
||||||
|
|
||||||
|
for i in data:
|
||||||
|
if i == 0:
|
||||||
|
numbers[0] += 1
|
||||||
|
if i == 1:
|
||||||
|
numbers[1] += 1
|
||||||
|
if i == 2:
|
||||||
|
numbers[2] += 1
|
||||||
|
if i == 3:
|
||||||
|
numbers[3] += 1
|
||||||
|
if i == 4:
|
||||||
|
numbers[4] += 1
|
||||||
|
if i == 5:
|
||||||
|
numbers[5] += 1
|
||||||
|
if i == 6:
|
||||||
|
numbers[6] += 1
|
||||||
|
if i == 7:
|
||||||
|
numbers[7] += 1
|
||||||
|
if i == 8:
|
||||||
|
numbers[8] += 1
|
||||||
|
|
||||||
|
def rotate(l):
|
||||||
|
return l[1:] + l[:1]
|
||||||
|
|
||||||
|
for j in range(256):
|
||||||
|
numbers = rotate(numbers)
|
||||||
|
numbers[6] += numbers[8]
|
||||||
|
print(f'DAY {j+1} AMOUNT OF FISH: {sum(numbers)}')
|
1
day6/input.txt
Normal file
1
day6/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
3,5,3,5,1,3,1,1,5,5,1,1,1,2,2,2,3,1,1,5,1,1,5,5,3,2,2,5,4,4,1,5,1,4,4,5,2,4,1,1,5,3,1,1,4,1,1,1,1,4,1,1,1,1,2,1,1,4,1,1,1,2,3,5,5,1,1,3,1,4,1,3,4,5,1,4,5,1,1,4,1,3,1,5,1,2,1,1,2,1,4,1,1,1,4,4,3,1,1,1,1,1,4,1,4,5,2,1,4,5,4,1,1,1,2,2,1,4,4,1,1,4,1,1,1,2,3,4,2,4,1,1,5,4,2,1,5,1,1,5,1,2,1,1,1,5,5,2,1,4,3,1,2,2,4,1,2,1,1,5,1,3,2,4,3,1,4,3,1,2,1,1,1,1,1,4,3,3,1,3,1,1,5,1,1,1,1,3,3,1,3,5,1,5,5,2,1,2,1,4,2,3,4,1,4,2,4,2,5,3,4,3,5,1,2,1,1,4,1,3,5,1,4,1,2,4,3,1,5,1,1,2,2,4,2,3,1,1,1,5,2,1,4,1,1,1,4,1,3,3,2,4,1,4,2,5,1,5,2,1,4,1,3,1,2,5,5,4,1,2,3,3,2,2,1,3,3,1,4,4,1,1,4,1,1,5,1,2,4,2,1,4,1,1,4,3,5,1,2,1
|
Loading…
Reference in New Issue
Block a user