From ff4ebd9f66da3ec07d2d3e8cfd8bf2289674bd83 Mon Sep 17 00:00:00 2001 From: David Vereb Date: Tue, 7 Dec 2021 14:28:54 -0500 Subject: [PATCH] Day 6 part 1. --- 2021/6/data | 1 + 2021/6/example_data | 1 + 2021/6/main.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 2021/6/data create mode 100644 2021/6/example_data create mode 100644 2021/6/main.py diff --git a/2021/6/data b/2021/6/data new file mode 100644 index 0000000..462025b --- /dev/null +++ b/2021/6/data @@ -0,0 +1 @@ +3,1,4,2,1,1,1,1,1,1,1,4,1,4,1,2,1,1,2,1,3,4,5,1,1,4,1,3,3,1,1,1,1,3,3,1,3,3,1,5,5,1,1,3,1,1,2,1,1,1,3,1,4,3,2,1,4,3,3,1,1,1,1,5,1,4,1,1,1,4,1,4,4,1,5,1,1,4,5,1,1,2,1,1,1,4,1,2,1,1,1,1,1,1,5,1,3,1,1,4,4,1,1,5,1,2,1,1,1,1,5,1,3,1,1,1,2,2,1,4,1,3,1,4,1,2,1,1,1,1,1,3,2,5,4,4,1,3,2,1,4,1,3,1,1,1,2,1,1,5,1,2,1,1,1,2,1,4,3,1,1,1,4,1,1,1,1,1,2,2,1,1,5,1,1,3,1,2,5,5,1,4,1,1,1,1,1,2,1,1,1,1,4,5,1,1,1,1,1,1,1,1,1,3,4,4,1,1,4,1,3,4,1,5,4,2,5,1,2,1,1,1,1,1,1,4,3,2,1,1,3,2,5,2,5,5,1,3,1,2,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,4,1,4,2,1,3,4,1,1,1,2,3,1,1,1,4,1,2,5,1,2,1,5,1,1,2,1,2,1,1,1,1,4,3,4,1,5,5,4,1,1,5,2,1,3 \ No newline at end of file diff --git a/2021/6/example_data b/2021/6/example_data new file mode 100644 index 0000000..a7af2b1 --- /dev/null +++ b/2021/6/example_data @@ -0,0 +1 @@ +3,4,3,1,2 \ No newline at end of file diff --git a/2021/6/main.py b/2021/6/main.py new file mode 100644 index 0000000..8db92e9 --- /dev/null +++ b/2021/6/main.py @@ -0,0 +1,30 @@ +def SimulateFish(days_until_next_fish, total_days_left): + print('SimulateFish(', days_until_next_fish, ',', total_days_left, ')') + # If we're past the final date, don't count any more: + if(total_days_left - days_until_next_fish <= 0): + # add 1 for THIS fish + return 1 + + total = 0 + # Add up all the totals of the fish this one is going to spawn + for i in range(total_days_left - days_until_next_fish, 0, -7): + total += SimulateFish(9, i) + # Add this fish, as well + total += 1 + + # Return grand total from this fish (INCLUDING this fish) + return total + + + +#### MAIN EXECUTION #### +fish = [] +with open('data', 'r') as fp: + fish = fp.readline().strip().split(',') + +grand_total = 0 +for i in range(0, len(fish)): + grand_total += SimulateFish(int(fish[i]), 80) + +print(grand_total) +