summaryrefslogtreecommitdiffstats
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/__init__.py39
-rw-r--r--day1/example.txt14
-rw-r--r--day1/input.txt2244
3 files changed, 2297 insertions, 0 deletions
diff --git a/day1/__init__.py b/day1/__init__.py
new file mode 100644
index 0000000..d7c995c
--- /dev/null
+++ b/day1/__init__.py
@@ -0,0 +1,39 @@
1from abc import ABC
2from itertools import groupby
3from typing import Iterator, Any, List
4
5from aoc import BaseAssignment
6
7class Assignment(BaseAssignment, ABC):
8 def calculate_elf_calories(self, input: Iterator) -> List[int]:
9 return [
10 sum([
11 int(i)
12 for i
13 in group
14 ])
15 for in_group, group
16 in groupby(input, key=bool)
17 if in_group
18 ]
19
20
21class AssignmentOne(Assignment):
22 example_result = 24000
23
24 def run(self, input: Iterator) -> int:
25 return max(self.calculate_elf_calories(input))
26
27
28class AssignmentTwo(Assignment):
29 example_result = 45000
30
31 def run(self, input: Iterator) -> int:
32 return sum(
33 sorted(
34 self.calculate_elf_calories(input),
35 reverse=True
36 )[:3]
37 )
38
39
diff --git a/day1/example.txt b/day1/example.txt
new file mode 100644
index 0000000..2094f91
--- /dev/null
+++ b/day1/example.txt
@@ -0,0 +1,14 @@
11000
22000
33000
4
54000
6
75000
86000
9
107000
118000
129000
13
1410000
diff --git a/day1/input.txt b/day1/input.txt
new file mode 100644
index 0000000..ff8b32b
--- /dev/null
+++ b/day1/input.txt
@@ -0,0 +1,2244 @@
12832
22108
33082
44328
56843
65121
72869
81366
92358
101680
114980
121161
13
148026
152154
164242
171023
182744
193162
204093
211150
225397
232738
245657
25
2610954
2711208
288034
291636
309430
319421
325025
33
343837
355938
363967
372942
382727
393623
404070
411748
421795
431687
444023
456068
462558
472570
484214
49
509679
512986
525168
5316463
54
555912
566008
571259
585378
5910740
601642
612617
627821
63
643840
655265
662104
671510
685477
692636
705920
715939
725430
734482
745603
754915
765416
775897
78
793932
809344
817536
824925
8310088
845253
855625
866800
87
883928
8913714
9018995
913569
92
932424
945188
9511199
966078
9711525
985155
993142
100
1012595
1025893
1035590
1046270
1056095
1065279
1073726
1086015
1093985
1105455
1115190
1124897
1136632
114
1155046
1161424
1173629
1186204
1196187
1201149
1214145
1226953
1232958
1246312
1251592
1264614
1272859
128
1295750
1309606
13111706
1322629
13313635
1345611
135
1362162
1376014
1383168
1398052
14010781
1413762
1425653
143
14421918
14514739
146
1472431
1485955
1494810
1507476
1512529
1527985
1536040
1545864
1553459
1563347
1574853
158
1594695
1603911
1615590
1624439
1634874
1642251
1653967
1666895
1675801
1682720
1695125
1705575
1712057
172
1735642
1743714
1755127
1765083
1772925
1785048
1796368
1805883
1812287
1823276
1833326
1842207
1853377
186
18718373
1887075
18912254
19018539
191
19213758
19319556
19423565
195
1966463
1975076
1985429
1993105
2006201
2015959
2026474
2035740
2046997
2057567
2061883
207
2082316
20910793
2102985
21110596