/day06.ipynb Secret
Created
December 6, 2021 12:41
AoC 2021 - Day 6
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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