day 6
This commit is contained in:
parent
c9cada67e8
commit
52d5b363ca
38
6/a.py
Normal file
38
6/a.py
Normal file
@ -0,0 +1,38 @@
|
||||
with open("input.txt") as f:
|
||||
pond = [int(i) for i in f.read().strip().split(",")]
|
||||
|
||||
print("pond", pond)
|
||||
|
||||
|
||||
def simulate():
|
||||
for i, fish in enumerate(pond[:]):
|
||||
# print("i, fish", i, fish)
|
||||
newfish = fish - 1
|
||||
if newfish < 0:
|
||||
newfish = 6
|
||||
pond.append(8)
|
||||
pond[i] = newfish
|
||||
|
||||
|
||||
for i in range(0, 80):
|
||||
# print("pond", len(pond))
|
||||
simulate()
|
||||
|
||||
print("answer", len(pond))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# each lanternfish creates a new lanternfish once every 7 days.
|
||||
|
||||
# So, you can model each fish as a single number that represents the number of days until it creates a new lanternfish.
|
||||
|
||||
# a new lanternfish would surely need slightly longer before it's capable of producing more lanternfish: two more days for its first cycle.
|
||||
|
||||
# list of the ages of several hundred nearby lanternfish (your puzzle input).
|
||||
|
||||
# Find a way to simulate lanternfish. How many lanternfish would there be after 80 days?
|
||||
|
||||
|
||||
|
29
6/b.py
Normal file
29
6/b.py
Normal file
@ -0,0 +1,29 @@
|
||||
from collections import defaultdict
|
||||
|
||||
with open("input.txt") as f:
|
||||
pond = [int(i) for i in f.read().strip().split(",")]
|
||||
|
||||
sea = defaultdict(lambda: 0)
|
||||
|
||||
|
||||
for fish in pond:
|
||||
sea[fish] += 1
|
||||
|
||||
|
||||
for i in range(0, 256):
|
||||
# print(i, dict(sea))
|
||||
newsea = defaultdict(lambda: 0)
|
||||
|
||||
for fish, count in sea.items():
|
||||
newfish = fish - 1
|
||||
if newfish < 0:
|
||||
newfish = 6
|
||||
newsea[8] += count
|
||||
newsea[newfish] += count
|
||||
|
||||
sea = newsea
|
||||
# print(i, dict(sea))
|
||||
# print()
|
||||
|
||||
|
||||
print(sum(sea.values()))
|
1
6/input.txt
Normal file
1
6/input.txt
Normal file
@ -0,0 +1 @@
|
||||
1,1,5,2,1,1,5,5,3,1,1,1,1,1,1,3,4,5,2,1,2,1,1,1,1,1,1,1,1,3,1,1,5,4,5,1,5,3,1,3,2,1,1,1,1,2,4,1,5,1,1,1,4,4,1,1,1,1,1,1,3,4,5,1,1,2,1,1,5,1,1,4,1,4,4,2,4,4,2,2,1,2,3,1,1,2,5,3,1,1,1,4,1,2,2,1,4,1,1,2,5,1,3,2,5,2,5,1,1,1,5,3,1,3,1,5,3,3,4,1,1,4,4,1,3,3,2,5,5,1,1,1,1,3,1,5,2,1,3,5,1,4,3,1,3,1,1,3,1,1,1,1,1,1,5,1,1,5,5,2,1,5,1,4,1,1,5,1,1,1,5,5,5,1,4,5,1,3,1,2,5,1,1,1,5,1,1,4,1,1,2,3,1,3,4,1,2,1,4,3,1,2,4,1,5,1,1,1,1,1,3,4,1,1,5,1,1,3,1,1,2,1,3,1,2,1,1,3,3,4,5,3,5,1,1,1,1,1,1,1,1,1,5,4,1,5,1,3,1,1,2,5,1,1,4,1,1,4,4,3,1,2,1,2,4,4,4,1,2,1,3,2,4,4,1,1,1,1,4,1,1,1,1,1,4,1,5,4,1,5,4,1,1,2,5,5,1,1,1,5
|
Loading…
x
Reference in New Issue
Block a user