Day 6 part 1.
This commit is contained in:
		
							
								
								
									
										1
									
								
								2021/6/data
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								2021/6/data
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
							
								
								
									
										1
									
								
								2021/6/example_data
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								2021/6/example_data
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					3,4,3,1,2
 | 
				
			||||||
							
								
								
									
										30
									
								
								2021/6/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								2021/6/main.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
		Reference in New Issue
	
	Block a user