Created
December 1, 2021 13:10
-
-
Save raeq/431f55759cb5b493d690cb948e823d92 to your computer and use it in GitHub Desktop.
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
import more_itertools | |
def get_data(filename: str) -> list: | |
with open(filename, 'r') as f: | |
return [int(line.rstrip('\n')) for line in f] | |
def make_couples(singles: list) -> list: | |
return zip(singles, singles[1:]) | |
def count_increases(couples: list) -> int: | |
return sum(next > prev for prev, next in couples) | |
if __name__ == "__main__": | |
data = get_data("day01.txt") | |
depths_couples = make_couples(data) | |
num_increases = count_increases(depths_couples) | |
print(f'Day 1 Star 1 answer: {num_increases}') | |
triples = [sum(triple) for triple in more_itertools.triplewise(data)] | |
windowed_couples = make_couples(triples) | |
num_increases = count_increases(windowed_couples) | |
print(f'Day 1 Star 2 answer: {num_increases}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment