Skip to content

Instantly share code, notes, and snippets.

@TheShallowOne
Created December 6, 2021 12:41
Show Gist options
  • Save TheShallowOne/323e8b0b90d62bd73232d84dec334933 to your computer and use it in GitHub Desktop.
Save TheShallowOne/323e8b0b90d62bd73232d84dec334933 to your computer and use it in GitHub Desktop.
AoC 2021 - Day 6
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
input = [3, 4, 3, 1, 2]
def number_in_generation(generation, days):
if days < 9 * generation:
return 0
steps = (days - 9 * generation) // 7 + 1
count = 1
for i in range(0, generation + 1):
count = count * (steps + i) // (1 + i)
return count
def calculate_total(days):
count = 1
for gen in range(days):
num = number_in_generation(gen, days)
if num == 0:
break
count += num
return count
def calculate_with_offset(startvalue, days):
days -= startvalue
if days <= 0:
return 1
else:
return calculate_total(days-1)
def calculate(input, days):
counts = [calculate_with_offset(x, days) for x in input]
return sum(counts)
part1 = calculate(input, 80)
part2 = calculate(input, 256)
print("Part 1:", part1)
print("Part 2:", part2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment