diff options
| author | 2022-12-23 22:01:57 +0100 | |
|---|---|---|
| committer | 2022-12-23 22:02:18 +0100 | |
| commit | 1cf8cf3f2182bb010b60f7c916fe2cd030df1658 (patch) | |
| tree | 6a4c0032bbf5f014bacd09c63fa01c8d9b156b6e /day20 | |
| parent | a5ddfacd0edffa6bcafa651ba9a51fffc1a14d86 (diff) | |
| download | 2022-1cf8cf3f2182bb010b60f7c916fe2cd030df1658.tar.gz 2022-1cf8cf3f2182bb010b60f7c916fe2cd030df1658.tar.bz2 2022-1cf8cf3f2182bb010b60f7c916fe2cd030df1658.zip | |
Day 20 [WIP]
Diffstat (limited to 'day20')
| -rw-r--r-- | day20/__init__.py | 61 | ||||
| -rw-r--r-- | day20/example.txt | 7 | ||||
| -rw-r--r-- | day20/input.txt | 5000 | ||||
| -rw-r--r-- | day20/test_init.py | 27 |
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 -*- | ||
| 2 | from abc import ABC | ||
| 3 | from collections import OrderedDict | ||
| 4 | from typing import Iterator, List | ||
| 5 | |||
| 6 | from aoc import BaseAssignment, I, T | ||
| 7 | |||
| 8 | |||
| 9 | class Assignment(BaseAssignment[int, int], ABC): | ||
| 10 | def parse_item(self, item: str) -> int: | ||
| 11 | return int(item) | ||
| 12 | |||
| 13 | |||
| 14 | class 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 | |||
| 60 | class 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 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | -3 | ||
| 4 | 3 | ||
| 5 | -2 | ||
| 6 | 0 | ||
| 7 | 4 | ||
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 | ||
| 2 | 1055 | ||
| 3 | 9806 | ||
| 4 | -52 | ||
| 5 | 9756 | ||
| 6 | 5575 | ||
| 7 | -6868 | ||
| 8 | 9680 | ||
| 9 | -3207 | ||
| 10 | 4001 | ||
| 11 | -8161 | ||
| 12 | -9566 | ||
| 13 | -1226 | ||
| 14 | 1900 | ||
| 15 | 2866 | ||
| 16 | 4187 | ||
| 17 | 1654 | ||
| 18 | 3617 | ||
| 19 | 8849 | ||
| 20 | -9914 | ||
| 21 | 8521 | ||
| 22 | 8120 | ||
| 23 | -5169 | ||
| 24 | -7619 | ||
| 25 | -7535 | ||
| 26 | 7495 | ||
| 27 | 5664 | ||
| 28 | -8496 | ||
| 29 | -5686 | ||
| 30 | -2536 | ||
| 31 | 3805 | ||
| 32 | 6796 | ||
| 33 | 8547 | ||
| 34 | -1566 | ||
| 35 | 1763 | ||
| 36 | 185 | ||
| 37 | -8474 | ||
| 38 | -8685 | ||
| 39 | -620 | ||
| 40 | 6756 | ||
| 41 | 8177 | ||
| 42 | 8512 | ||
| 43 | 396 | ||
| 44 | -9955 | ||
| 45 | 3824 | ||
| 46 | -944 | ||
| 47 | 2517 | ||
| 48 | -8040 | ||
| 49 | 5240 | ||
| 50 | 3069 | ||
| 51 | -6780 | ||
| 52 | 8507 | ||
| 53 | -441 | ||
| 54 | -5563 | ||
| 55 | -6580 | ||
| 56 | -871 | ||
| 57 | -3887 | ||
| 58 | -9017 | ||
| 59 | -3223 | ||
| 60 | 8781 | ||
| 61 | -2683 | ||
| 62 | 4879 | ||
| 63 | 3489 | ||
| 64 | -2162 | ||
| 65 | 5845 | ||
| 66 | -522 | ||
| 67 | -100 | ||
| 68 | -3908 | ||
| 69 | -3454 | ||
| 70 | 9431 | ||
| 71 | 1772 | ||
| 72 | 8318 | ||
| 73 | 6915 | ||
| 74 | -3412 | ||
| 75 | -8940 | ||
| 76 | 3625 | ||
| 77 | -747 | ||
| 78 | -93 | ||
| 79 | 7892 | ||
| 80 | 1250 | ||
| 81 | -8964 | ||
| 82 | 1441 | ||
| 83 | 1461 | ||
| 84 | 9017 | ||
| 85 | 3088 | ||
| 86 | 7405 | ||
| 87 | 1726 | ||
| 88 | -4060 | ||
| 89 | 6932 | ||
| 90 | 4112 | ||
| 91 | 4094 | ||
| 92 | -9703 | ||
| 93 | -2374 | ||
| 94 | 6725 | ||
| 95 | -561 | ||
| 96 | -843 | ||
| 97 | -1936 | ||
| 98 | 4973 | ||
| 99 | 2838 | ||
| 100 | -6085 | ||
| 101 | -9957 | ||
| 102 | -6014 | ||
| 103 | -6600 | ||
| 104 | -1363 | ||
| 105 | 2675 | ||
| 106 | 8525 | ||
| 107 | 9136 | ||
| 108 | -6674 | ||
| 109 | -6646 | ||
| 110 | -3119 | ||
| 111 | 7283 | ||
| 112 | 506 | ||
| 113 | -5932 | ||
| 114 | 353 | ||
| 115 | 9108 | ||
| 116 | -2531 | ||
| 117 | -8120 | ||
| 118 | -4082 | ||
| 119 | -3503 | ||
| 120 | 5596 | ||
| 121 | -3053 | ||
| 122 | 1505 | ||
| 123 | 6886 | ||
| 124 | 9246 | ||
| 125 | -3775 | ||
| 126 | 3476 | ||
| 127 | 6760 | ||
| 128 | -4143 | ||
| 129 | -7524 | ||
| 130 | 398 | ||
| 131 | -4137 | ||
| 132 | 162 | ||
| 133 | 8094 | ||
| 134 | 7805 | ||
| 135 | 8702 | ||
| 136 | 363 | ||
| 137 | 7621 | ||
| 138 | -2204 | ||
| 139 | -5146 | ||
| 140 | 6176 | ||
| 141 | -6085 | ||
| 142 | 1571 | ||
| 143 | 6284 | ||
| 144 | -8783 | ||
| 145 | -5776 | ||
| 146 | 3058 | ||
| 147 | 5006 | ||
| 148 | 1497 | ||
| 149 | -6818 | ||
| 150 | -6673 | ||
| 151 | -4238 | ||
| 152 | -1158 | ||
| 153 | -4137 | ||
| 154 | 5787 | ||
| 155 | 6159 | ||
| 156 | -8251 | ||
| 157 | -7193 | ||
| 158 | -8504 | ||
| 159 | -2985 | ||
| 160 | 7111 | ||
| 161 | -6426 | ||
| 162 | -609 | ||
| 163 | -6221 | ||
| 164 | 641 | ||
| 165 | -2569 | ||
| 166 | -6092 | ||
| 167 | 8744 | ||
| 168 | 2435 | ||
| 169 | -5082 | ||
| 170 | 4909 | ||
| 171 | -9216 | ||
| 172 | 1782 | ||
| 173 | 7040 | ||
| 174 | -7788 | ||
| 175 | -772 | ||
| 176 | 8750 | ||
| 177 | 7263 | ||
| 178 | -8535 | ||
| 179 | -4503 | ||
| 180 | -30 | ||
| 181 | 6088 | ||
| 182 | 5094 | ||
| 183 | -6322 | ||
