AdventOfCode/days1-5/day1/day1.py

26 lines
819 B
Python
Raw Normal View History

2022-12-01 23:49:25 +00:00
def main():
2022-12-25 15:10:36 +00:00
with open('input.txt', 'r') as f:
2022-12-01 23:49:25 +00:00
# Part 1
calories = [line for line in f.read().split('\n')]
caloriesPerDay = [0] * len(calories)
index = 0
for calorie in calories:
if calorie == '':
index += 1
else:
caloriesPerDay[index] += int(calorie)
nOfElfs = caloriesPerDay.index(0)
caloriesPerElf = caloriesPerDay[:nOfElfs]
print(f"Top elf calorie count: {max(caloriesPerElf)}")
# Part 2
sumOfCaloriesOfTopThree = []
for i in range(3):
sumOfCaloriesOfTopThree.append(max(caloriesPerElf))
caloriesPerElf.remove(max(caloriesPerElf))
print(f"Sum of top three elfs: {sum(sumOfCaloriesOfTopThree)}")
if __name__ == '__main__':
main()