File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ def part1 (lines ):
2
+ inventories = []
3
+ current = []
4
+ for line in lines :
5
+ if line == '\n ' :
6
+ inventories .append (current )
7
+ current = []
8
+ continue
9
+ else :
10
+ current .append (int (line ))
11
+
12
+ max_calories = 0
13
+
14
+ for inventory in inventories :
15
+ s = sum (inventory )
16
+ if s > max_calories :
17
+ max_calories = s
18
+
19
+ return max_calories
20
+
21
+ def part2 (lines ):
22
+ inventories = []
23
+ current = []
24
+ for line in lines :
25
+ if line == '\n ' :
26
+ inventories .append (current )
27
+ current = []
28
+ continue
29
+ else :
30
+ current .append (int (line ))
31
+
32
+ calories = []
33
+ for inventory in inventories :
34
+ calories .append (sum (inventory ))
35
+
36
+ calories .sort (reverse = True )
37
+ return sum (calories [0 :3 ])
38
+
39
+ with open ('../input.txt' ) as f :
40
+ lines = f .readlines ()
41
+
42
+ print (part1 (lines ))
43
+ print (part2 (lines ))
You can’t perform that action at this time.
0 commit comments