Created
December 1, 2022 08:59
-
-
Save grabovszky/e64cc4a15ace642ffa7382cdb78418e4 to your computer and use it in GitHub Desktop.
Advent of Code 2022 Day 1 Task 2
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
data = open("input.txt").read() | |
current_carried = 0 | |
sum_carried_by_one = [] | |
for food in data.split("\n"): | |
if len(food) == 0: | |
sum_carried_by_one.append(current_carried) | |
current_carried = 0 | |
else: | |
current_carried += int(food) | |
sum_carried_by_one.append(current_carried) | |
sum_carried_by_one.sort() | |
sum_of_three_biggest = ( | |
sum_carried_by_one[-1] + sum_carried_by_one[-2] + sum_carried_by_one[-3] | |
) | |
print(sum_of_three_biggest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment