Add Day 1

This commit is contained in:
2022-12-01 08:00:54 +00:00
parent 92d899d627
commit b2b131b6ad
2 changed files with 2272 additions and 0 deletions

30
day1/day1.py Normal file
View File

@@ -0,0 +1,30 @@
# Day 1 - Calorie Counting
# https://adventofcode.com/2022/day/1
elves = []
with open('input.txt', 'r') as fobj:
total_calories = 0
# Iterate the file, and build the totals
for line in fobj.readlines():
if line.strip() == '':
elves.append(total_calories)
total_calories = 0
else:
total_calories += int(line)
# Add the last elf of the file
elves.append(total_calories)
# Sort the elves
elves = sorted(elves, reverse=True)
print('Total Calories: {0}'.format(sum(elves)))
print('Total Elves: {0}'.format(len(elves)))
# Part 1 - Top elf
print('Highest Calories Elf: {0}'.format(max(elves)))
# Part 2 - Top 3 elves
print('Top 3 Elves Total: {0}'.format(sum(elves[:3])))

2242
day1/input.txt Normal file

File diff suppressed because it is too large Load Diff