summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--day20/__init__.py61
-rw-r--r--day20/example.txt7
-rw-r--r--day20/input.txt5000
-rw-r--r--day20/test_init.py27
4 files changed, 5095 insertions, 0 deletions
diff --git a/day20/__init__.py b/day20/__init__.py
new file mode 100644
index 0000000..02ff80d
--- /dev/null
+++ b/day20/__init__.py
@@ -0,0 +1,61 @@
1# -*- coding: utf-8 -*-
2from abc import ABC
3from collections import OrderedDict
4from typing import Iterator, List
5
6from aoc import BaseAssignment, I, T
7
8
9class Assignment(BaseAssignment[int, int], ABC):
10 def parse_item(self, item: str) -> int:
11 return int(item)
12
13
14class AssignmentOne(Assignment):
15 example_result = 3
16
17 @staticmethod
18 def move(items: List[int], item: int):
19 items = list(items)
20 input_size = len(items)
21
22 index = items.index(item)
23 item = items.pop(index)
24
25 new_index = (index + item) % input_size
26
27 if item > 0 and index + item >= input_size:
28 new_index += 1
29
30 if item < 0 and index + item <= 0:
31 new_index -= 1
32
33 items.insert(new_index, item)
34
35 return items
36
37 def run(self, input: Iterator[I]) -> T:
38 input_list = list(input)
39 input_size = len(input_list)
40 working_list = list(input_list)
41
42 for index, item in enumerate(input_list):
43 working_list = self.move(working_list, item)
44
45 print(
46 working_list[1000 % input_size],
47 working_list[2000 % input_size],
48 working_list[3000 % input_size],
49 )
50
51 return sum(
52 [
53 working_list[1000 % input_size],
54 working_list[2000 % input_size],
55 working_list[3000 % input_size],
56 ]
57 )
58
59
60class AssignmentTwo(Assignment):
61 pass
diff --git a/day20/example.txt b/day20/example.txt
new file mode 100644
index 0000000..52c68ff
--- /dev/null
+++ b/day20/example.txt
@@ -0,0 +1,7 @@
11
22
3-3
43
5-2
60
74
diff --git a/day20/input.txt b/day20/input.txt
new file mode 100644
index 0000000..d79c61b
--- /dev/null
+++ b/day20/input.txt
@@ -0,0 +1,5000 @@
1-9405
21055
39806
4-52
59756
65575
7-6868
89680
9-3207
104001
11-8161
12-9566
13-1226
141900
152866
164187
171654
183617
198849
20-9914
218521
228120
23-5169
24-7619
25-7535
267495
275664
28-8496
29-5686
30-2536
313805
326796
338547
34-1566
351763
36185
37-8474
38-8685
39-620
406756
418177
428512
43396
44-9955
453824
46-944
472517
48-8040
495240
503069
51-6780
528507
53-441
54-5563
55-6580
56-871
57-3887
58-9017
59-3223
608781
61-2683
624879
633489
64-2162
655845
66-522
67-100
68-3908
69-3454
709431
711772
728318
736915
74-3412
75-8940
763625
77-747
78-93
797892
801250
81-8964
821441
831461
849017
853088
867405
871726
88-4060
896932
904112
914094
92-9703
93-2374
946725
95-561
96-843
97-1936
984973
992838
100-6085
101-9957
102-6014
103-6600
104-1363
1052675
1068525
1079136
108-6674
109-6646
110-3119
1117283
112506
113-5932
114353
1159108
116-2531
117-8120
118-4082
119-3503
1205596
121-3053
1221505
1236886
1249246
125-3775
1263476
1276760
128-4143
129-7524
130398
131-4137
132162
1338094
1347805
1358702
136363
1377621
138-2204
139-5146
1406176
141-6085
1421571
1436284
144-8783
145-5776
1463058
1475006
1481497
149-6818
150-6673
151-4238
152-1158
153-4137
1545787
1556159
156-8251
157-7193
158-8504
159-2985
1607111
161-6426
162-609
163-6221
164641
165-2569
166-6092
1678744
1682435
169-5082
1704909
171-9216
1721782
1737040
174-7788
175-772
1768750
1777263
178-8535
179-4503
180-30
1816088
1825094
183-6322
1843881
1851789
1866819
1876806
1886914
189645
1907828
1917906