-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd1p1.py
40 lines (31 loc) · 998 Bytes
/
d1p1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from typing import List
import copy
ElvesWithCalorieItems = List[List[int]]
def parse_input(message: str) -> ElvesWithCalorieItems:
# parse string into lines
lines = message.splitlines()
# group strings by empty string
groups = []
group = []
for line in lines:
if line == "":
groups.append(group)
group = []
else:
group.append(line)
groups.append(group)
# convert groups of strings to integers
elves_with_calorie_items = []
for group in groups:
calorie_items = []
for line in group:
calorie_items.append(int(line))
elves_with_calorie_items.append(calorie_items)
return elves_with_calorie_items
def get_max_calories_for_one_elf(elves: ElvesWithCalorieItems) -> int:
# sum calories per elve
calories_per_elve = []
for elve in elves:
calories_per_elve.append(sum(elve))
# get max calories per elve
return max(calories_per_elve)