mirror of
https://github.com/nikdoof/aoc2022.git
synced 2026-01-29 23:08:14 +00:00
Add Day 1
This commit is contained in:
30
day1/day1.py
Normal file
30
day1/day1.py
Normal 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
2242
day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user