diff --git a/6/a.py b/6/a.py new file mode 100644 index 0000000..3aadb0b --- /dev/null +++ b/6/a.py @@ -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? + + + diff --git a/6/b.py b/6/b.py new file mode 100644 index 0000000..af6cca3 --- /dev/null +++ b/6/b.py @@ -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())) \ No newline at end of file diff --git a/6/input.txt b/6/input.txt new file mode 100644 index 0000000..777f8fb --- /dev/null +++ b/6/input.txt @@ -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