Day 1 challenges added

This commit is contained in:
TiagoRG 2022-12-01 23:49:25 +00:00
parent eda868eb31
commit 7bcb9a9e80
2 changed files with 2275 additions and 0 deletions

2250
days1-5/day1/calories Normal file

File diff suppressed because it is too large Load Diff

25
days1-5/day1/day1.py Normal file
View File

@ -0,0 +1,25 @@
def main():
with open('calories', 'r') as f:
# 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()