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)