diff options
Diffstat (limited to 'day9')
| -rw-r--r-- | day9/__init__.py | 63 | ||||
| -rw-r--r-- | day9/example.txt | 20 | ||||
| -rw-r--r-- | day9/input.txt | 1000 |
3 files changed, 0 insertions, 1083 deletions
diff --git a/day9/__init__.py b/day9/__init__.py deleted file mode 100644 index 0cf3770..0000000 --- a/day9/__init__.py +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | from typing import Any, Iterator, List | ||
| 2 | |||
| 3 | from aoc import BaseAssignment | ||
| 4 | |||
| 5 | |||
| 6 | class Assignment(BaseAssignment): | ||
| 7 | def __init__(self, path, preamble_length=25): | ||
| 8 | super().__init__(path) | ||
| 9 | self.preamble_length = int(preamble_length) | ||
| 10 | |||
| 11 | def read_input(self, example=False) -> List: | ||
| 12 | return list(super(Assignment, self).read_input(example)) | ||
| 13 | |||
| 14 | def parse_item(self, item: str) -> Any: | ||
| 15 | return int(item) | ||
| 16 | |||
| 17 | |||
| 18 | class AssignmentOne(Assignment): | ||
| 19 | def find_invalid(self, input: List, preamble_length: int = 25) -> int: | ||
| 20 | preamble = sorted(input[:preamble_length]) | ||
| 21 | to_check = input[preamble_length] | ||
| 22 | |||
| 23 | front_position = 0 | ||
| 24 | end_position = preamble_length - 1 | ||
| 25 | |||
| 26 | while True: | ||
| 27 | if front_position is end_position: | ||
| 28 | return to_check | ||
| 29 | |||
| 30 | sum = preamble[front_position] + preamble[end_position] | ||
| 31 | |||
| 32 | if sum > to_check: | ||
| 33 | end_position -= 1 | ||
| 34 | elif sum < to_check: | ||
| 35 | front_position += 1 | ||
| 36 | else: | ||
| 37 | break | ||
| 38 | |||
| 39 | return self.find_invalid(input[1:], preamble_length=preamble_length) | ||
| 40 | |||
| 41 | def run(self, input: List) -> int: | ||
| 42 | return self.find_invalid( | ||
| 43 | input, preamble_length=int(self.preamble_length)) | ||
| 44 | |||
| 45 | |||
| 46 | class AssignmentTwo(AssignmentOne): | ||
| 47 | def find_weakness(self, input: List, invalid_nr: int) -> int: | ||
| 48 | for index, current_num in enumerate(input): | ||
| 49 | if index < 2: | ||
| 50 | continue | ||
| 51 | |||
| 52 | items_to_check = input[:index] | ||
| 53 | sum_list = sum(items_to_check) | ||
| 54 | |||
| 55 | if sum_list > invalid_nr: | ||
| 56 | break | ||
| 57 | elif sum_list == invalid_nr: | ||
| 58 | return min(items_to_check) + max(items_to_check) | ||
| 59 | |||
| 60 | return self.find_weakness(input[1:], invalid_nr) | ||
| 61 | |||
| 62 | def run(self, input: List) -> int: | ||
| 63 | return self.find_weakness(input, super().run(input)) | ||
diff --git a/day9/example.txt b/day9/example.txt deleted file mode 100644 index cda4246..0000000 --- a/day9/example.txt +++ /dev/null | |||
| @@ -1,20 +0,0 @@ | |||
| 1 | 35 | ||
| 2 | 20 | ||
| 3 | 15 | ||
| 4 | 25 | ||
| 5 | 47 | ||
| 6 | 40 | ||
| 7 | 62 | ||
| 8 | 55 | ||
| 9 | 65 | ||
| 10 | 95 | ||
| 11 | 102 | ||
| 12 | 117 | ||
| 13 | 150 | ||
| 14 | 182 | ||
| 15 | 127 | ||
| 16 | 219 | ||
| 17 | 299 | ||
| 18 | 277 | ||
| 19 | 309 | ||
| 20 | 576 \ No newline at end of file | ||
diff --git a/day9/input.txt b/day9/input.txt deleted file mode 100644 index e9932d5..0000000 --- a/day9/input.txt +++ /dev/null | |||
| @@ -1,1000 +0,0 @@ | |||
| 1 | 18 | ||
| 2 | 19 | ||
| 3 | 46 | ||
| 4 | 14 | ||
| 5 | 29 | ||
| 6 | 45 | ||
| 7 | 40 | ||
| 8 | 47 | ||
| 9 | 25 | ||
| 10 | 43 | ||
| 11 | 36 | ||
| 12 | 22 | ||
| 13 | 21 | ||
| 14 | 4 | ||
| 15 | 32 | ||
| 16 | 33 | ||
| 17 | 37 | ||
| 18 | 38 | ||
| 19 | 26 | ||
| 20 | 2 | ||
| 21 | 42 | ||
| 22 | 15 | ||
| 23 | 5 | ||
| 24 | 13 | ||
| 25 | 31 | ||
| 26 | 9 | ||
| 27 | 6 | ||
| 28 | 30 | ||
| 29 | 7 | ||
| 30 | 14 | ||
| 31 | 10 | ||
| 32 | 8 | ||
| 33 | 69 | ||
| 34 | 11 | ||
| 35 | 12 | ||
| 36 | 25 | ||
| 37 | 16 | ||
| 38 | 17 | ||
| 39 | 22 | ||
| 40 | 19 | ||
| 41 | 18 | ||
| 42 | 20 | ||
| 43 | 51 | ||
| 44 | 21 | ||
| 45 | 24 | ||
| 46 | 23 | ||
| 47 | 26 | ||
| 48 | 15 | ||
| 49 | 60 | ||
| 50 | 13 | ||
| 51 | 29 | ||
| 52 | 27 | ||
| 53 | 44 | ||
| 54 | 42 | ||
| 55 | 28 | ||
| 56 | 38 | ||
| 57 | 30 | ||
| 58 | 36 | ||
| 59 | 31 | ||
| 60 | 32 | ||
| 61 | 33 | ||
| 62 | 34 | ||
| 63 | 35 | ||
| 64 | 37 | ||
| 65 | 55 | ||
| 66 | 39 | ||
| 67 | 40 | ||
| 68 | 70 | ||
| 69 | 41 | ||
| 70 | 43 | ||
| 71 | 78 | ||
| 72 | 58 | ||
| 73 | 73 | ||
| 74 | 101 | ||
| 75 | 60 | ||
| 76 | 56 | ||
| 77 | 57 | ||
| 78 | 75 | ||
| 79 | 59 | ||
| 80 | 67 | ||
| 81 | 71 | ||
| 82 | 61 | ||
| 83 | 68 | ||
| 84 | 110 | ||
| 85 | 69 | ||
| 86 | 80 | ||
| 87 | 72 | ||
| 88 | 112 | ||
| 89 | 76 | ||
| 90 | 79 | ||
| 91 | 144 | ||
| 92 | 129 | ||
| 93 | 114 | ||
| 94 | 84 | ||
| 95 | 99 | ||
| 96 | 113 | ||
| 97 | 132 | ||
| 98 | 115 | ||
| 99 | 148 | ||
| 100 | 116 | ||
| 101 | 118 | ||
| 102 | 120 | ||
| 103 | 128 | ||
| 104 | 126 | ||
| 105 | 187 | ||
| 106 | 130 | ||
| 107 | 190 | ||
| 108 | 152 | ||
| 109 | 229 | ||
| 110 | 141 | ||
| 111 | 151 | ||
| 112 | 155 | ||
| 113 | 299 | ||
| 114 | 209 | ||
| 115 | 163 | ||
| 116 | 239 | ||
| 117 | 183 | ||
| 118 | 197 | ||
| 119 | 331 | ||
| 120 | 212 | ||
| 121 | 228 | ||
| 122 | 270 | ||
| 123 | 231 | ||
| 124 | 234 | ||
| 125 | 236 | ||
| 126 | 244 | ||
| 127 | 246 | ||
| 128 | 355 | ||
| 129 | 256 | ||
| 130 | 392 | ||
| 131 | 271 | ||
| 132 | 342 | ||
| 133 | 292 | ||
| 134 | 360 | ||
| 135 | 296 | ||
| 136 | 306 | ||
| 137 | 318 | ||
| 138 | 346 | ||
| 139 | 602 | ||
| 140 | 375 | ||
| 141 | 380 | ||
| 142 | 395 | ||
| 143 | 534 | ||
| 144 | 456 | ||
| 145 | 440 | ||
| 146 | 459 | ||
| 147 | 470 | ||
| 148 | 502 | ||
| 149 | 478 | ||
| 150 | 480 | ||
| 151 | 490 | ||
| 152 | 517 | ||
| 153 | 527 | ||
| 154 | 548 | ||
| 155 | 563 | ||
| 156 | 1082 | ||
| 157 | 1136 | ||
| 158 | 896 | ||
| 159 | 1044 | ||
| 160 | 614 | ||
| 161 | 693 | ||
| 162 | 698 | ||
| 163 | 988 | ||
| 164 | 755 | ||
| 165 | 1065 | ||
| 166 | 1352 | ||
| 167 | 835 | ||
| 168 | 899 | ||
| 169 | 915 | ||
| 170 | 942 | ||
| 171 | 929 | ||
| 172 | 1173 | ||
| 173 | 958 | ||
| 174 | 1043 | ||
| 175 | 970 | ||
| 176 | 1007 | ||
| 177 | 1075 | ||
| 178 | 1090 | ||
| 179 | 1529 | ||
