added solutions for 1.1, 1.2, 2.1, 2.2 and 3.1

This commit is contained in:
2022-12-08 02:01:15 +01:00
parent 7187676b9b
commit 16721db1bd
8 changed files with 9940 additions and 0 deletions

30
week1/calorie_counting.py Normal file
View File

@@ -0,0 +1,30 @@
def task1():
with open(f'input/calorie_counting.txt', 'r') as input:
sanitized_input = [x.replace('\n', '') for x in input.readlines()]
sum = 0
max = 0
for i in sanitized_input:
if i == '':
max = sum if sum > max else max
sum = 0
else:
sum += int(i)
print(max)
def task2():
with open(f'input/calorie_counting2.txt', 'r') as input:
sanitized_input = [x.replace('\n', '') for x in input.readlines()]
elves = [0]
elvesIndex = 0
for input in sanitized_input:
if input == '':
elvesIndex += 1
elves.append(0)
else:
elves[elvesIndex] += int(input)
elves.sort()
print(sum(elves[-3:]))
task1()
task2()