sample_data = [3,4,3,1,2]

def solve(data, days):

  # Initialize fish_counts
  # Fish counts is a Dictionary where the key is the age of each fish
  # and the value is the count of the fish at that age
  fish_counts = [0] * 9
  for n in data:
    fish_counts[n] += 1
    
  # Process fish each day
  for day in range(0, days):

    next_fish_counts = [0] * 9 # Rebuild the list of fish every day
    num_fish = 0 # Counts the total number of fish each day

    # Reproduction - parent resets to 6s, children are 8s
    next_fish_counts[6] = fish_counts[0]
    next_fish_counts[8] = fish_counts[0]
    
    # Count the new fish since they aren't included in the for loop below
    num_fish += next_fish_counts[8]

    # Shuffle all of the fish counts down one index
    for n in range(0, 8):
      next_fish_counts[n] += fish_counts[n + 1]
      num_fish += next_fish_counts[n]

    # Update fish_counts for the next day's processing
    fish_counts = next_fish_counts

    print(f"Day {day}: {num_fish}")

  return num_fish

# Import the data file into a list of lists of four elements reprenting x1,y1,x2,y2
values = []
with open ('day-06.txt', 'r') as f:
  str = f.readline()
  for s in str.split(','):
    values.append(int(s.strip()))

print('Problem 1 Sample Value (Target 26): {}'.format(solve(sample_data, 18)))
print('Problem 1 Sample Value (Target 5934): {}'.format(solve(sample_data, 80)))
print('Problem 1 Solution: {}'.format(solve(values, 80)))

print('Problem 2 Sample Value (Target 26984457539): {}'.format(solve(sample_data, 256)))
print('Problem 2 Solution: {}'.format(solve(values, 256)))

sample_data = [3,4,3,1,2]

def solve(data, days):

  # Initialize fish_counts
  # Fish counts is a Dictionary where the key is the age of each fish
  # and the value is the count of the fish at that age
  fish_counts = [0] * 9
  for n in data:
    fish_counts[n] += 1
    
  # Process fish each day
  for day in range(0, days):

    next_fish_counts = [0] * 9 # Rebuild the list of fish every day
    num_fish = 0 # Counts the total number of fish each day

    # Reproduction - parent resets to 6s, children are 8s
    next_fish_counts[6] = fish_counts[0]
    next_fish_counts[8] = fish_counts[0]
    
    # Count the new fish since they aren't included in the for loop below
    num_fish += next_fish_counts[8]

    # Shuffle all of the fish counts down one index
    for n in range(0, 8):
      next_fish_counts[n] += fish_counts[n + 1]
      num_fish += next_fish_counts[n]

    # Update fish_counts for the next day's processing
    fish_counts = next_fish_counts

    print(f"Day {day}: {num_fish}")

  return num_fish

# Import the data file into a list of lists of four elements reprenting x1,y1,x2,y2
values = []
with open ('day-06.txt', 'r') as f:
  str = f.readline()
  for s in str.split(','):
    values.append(int(s.strip()))

print('Problem 1 Sample Value (Target 26): {}'.format(solve(sample_data, 18)))
print('Problem 1 Sample Value (Target 5934): {}'.format(solve(sample_data, 80)))
print('Problem 1 Solution: {}'.format(solve(values, 80)))

print('Problem 2 Sample Value (Target 26984457539): {}'.format(solve(sample_data, 256)))
print('Problem 2 Solution: {}'.format(solve(values, 256)))

# Initialize fish_counts # Fish counts is a Dictionary where the key is the age of each fish # and the value is the count of the fish at that age # Process fish each day # Rebuild the list of fish every day # Counts the total number of fish each day # Reproduction - parent resets to 6s, children are 8s # Count the new fish since they aren't included in the for loop below # Shuffle all of the fish counts down one index # Update fish_counts for the next day's processing # Import the data file into a list of lists of four elements reprenting x1,y1,x2,y2