diff options
| -rw-r--r-- | day5/__init__.py | 74 | ||||
| -rw-r--r-- | day5/example.txt | 10 | ||||
| -rw-r--r-- | day5/input.txt | 500 | ||||
| -rw-r--r-- | day5/test_init.py | 15 |
4 files changed, 599 insertions, 0 deletions
diff --git a/day5/__init__.py b/day5/__init__.py new file mode 100644 index 0000000..4d5260d --- /dev/null +++ b/day5/__init__.py | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | from collections import Counter | ||
| 2 | from copy import copy | ||
| 3 | from dataclasses import dataclass | ||
| 4 | from typing import Iterator, List, Optional, Tuple, Callable | ||
| 5 | |||
| 6 | from aoc import BaseAssignment | ||
| 7 | |||
| 8 | Vector = Tuple[Tuple[int, int], Tuple[int, int]] | ||
| 9 | |||
| 10 | class Assignment(BaseAssignment): | ||
| 11 | def parse_item(self, item: str) -> Vector: | ||
| 12 | start, end = item.split('->') | ||
| 13 | return ( | ||
| 14 | tuple(int(_) for _ in start.strip().split(',')), | ||
| 15 | tuple(int(_) for _ in end.strip().split(',')), | ||
| 16 | ) | ||
| 17 | |||
| 18 | def read_input(self, example = False) -> List[Vector]: | ||
| 19 | return list(super().read_input(example)) | ||
| 20 | |||
| 21 | |||
| 22 | def is_horizontal(v: Vector): | ||
| 23 | return v[0][0] == v[1][0] | ||
| 24 | |||
| 25 | def is_vertical(v: Vector): | ||
| 26 | return v[0][1] == v[1][1] | ||
| 27 | |||
| 28 | def points_in_vector(vector: Vector) -> List[Tuple[int, int]]: | ||
| 29 | first_x = min(vector[0][0], vector[1][0]) | ||
| 30 | last_x = max(vector[0][0], vector[1][0]) | ||
| 31 | first_y = min(vector[0][1], vector[1][1]) | ||
| 32 | last_y = max(vector[0][1], vector[1][1]) | ||
| 33 | |||
| 34 | return [ | ||
| 35 | (vector[0][0], y) | ||
| 36 | for y | ||
| 37 | in range(first_y, last_y + 1) | ||
| 38 | ] if is_horizontal(vector) else [ | ||
| 39 | (x, vector[0][1]) | ||
| 40 | for x | ||
| 41 | in range(first_x, last_x + 1) | ||
| 42 | ] if is_vertical(vector) else [] | ||
| 43 | |||
| 44 | |||
| 45 | class AssignmentOne(Assignment): | ||
| 46 | example_result = 5 | ||
| 47 | |||
| 48 | def run(self, input: List[Vector]) -> int: | ||
| 49 | coordinates = [] | ||
| 50 | |||
| 51 | for vector in input: | ||
| 52 | coordinates += points_in_vector(vector) | ||
| 53 | |||
| 54 | return len([c for c in Counter(coordinates).values() if c >= 2]) | ||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | # class AssignmentTwo(Assignment): | ||
| 60 | # example_result = 1924 | ||
| 61 | # | ||
| 62 | # def run(self, input: Tuple[List[int], List[BingoCard]]) -> int: | ||
| 63 | # nrs, cards = input | ||
| 64 | # | ||
| 65 | # in_game = copy(cards) | ||
| 66 | # for nr in nrs: | ||
| 67 | # for card in copy(in_game): | ||
| 68 | # card.mark(nr) | ||
| 69 | # | ||
| 70 | # if card.bingo: | ||
| 71 | # in_game.remove(card) | ||
| 72 | # | ||
| 73 | # if len(in_game) == 0: | ||
| 74 | # return nr * sum(card.unmarked) \ No newline at end of file | ||
diff --git a/day5/example.txt b/day5/example.txt new file mode 100644 index 0000000..1d4e36d --- /dev/null +++ b/day5/example.txt | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | 0,9 -> 5,9 | ||
| 2 | 8,0 -> 0,8 | ||
| 3 | 9,4 -> 3,4 | ||
| 4 | 2,2 -> 2,1 | ||
| 5 | 7,0 -> 7,4 | ||
| 6 | 6,4 -> 2,0 | ||
| 7 | 0,9 -> 2,9 | ||
| 8 | 3,4 -> 1,4 | ||
| 9 | 0,0 -> 8,8 | ||
| 10 | 5,5 -> 8,2 \ No newline at end of file | ||
diff --git a/day5/input.txt b/day5/input.txt new file mode 100644 index 0000000..fc4f01d --- /dev/null +++ b/day5/input.txt | |||
| @@ -0,0 +1,500 @@ | |||
| 1 | 498,436 -> 498,932 | ||
| 2 | 173,176 -> 845,848 | ||
| 3 | 927,799 -> 927,418 | ||
| 4 | 576,67 -> 801,67 | ||
| 5 | 908,147 -> 743,147 | ||
| 6 | 300,478 -> 300,224 | ||
| 7 | 286,979 -> 286,310 | ||
| 8 | 230,435 -> 729,934 | ||
| 9 | 260,602 -> 260,56 | ||
| 10 | 82,686 -> 655,113 | ||
| 11 | 460,918 -> 460,224 | ||
| 12 | 191,820 -> 454,820 | ||
| 13 | 964,483 -> 964,772 | ||
| 14 | 395,705 -> 142,705 | ||
| 15 | 281,563 -> 134,563 | ||
| 16 | 155,509 -> 152,509 | ||
| 17 | 754,586 -> 742,586 | ||
| 18 | 620,114 -> 620,775 | ||
| 19 | 450,476 -> 450,212 | ||
| 20 | 135,845 -> 591,845 | ||
| 21 | 922,902 -> 110,90 | ||
| 22 | 562,71 -> 895,71 | ||
| 23 | 843,13 -> 843,620 | ||
| 24 | 413,398 -> 486,471 | ||
| 25 | 206,601 -> 409,398 | ||
| 26 | 854,813 -> 65,813 | ||
| 27 | 625,17 -> 293,349 | ||
| 28 | 778,807 -> 778,145 | ||
| 29 | 372,655 -> 566,655 | ||
| 30 | 520,490 -> 520,289 | ||
| 31 | 450,787 -> 450,717 | ||
| 32 | 416,649 -> 826,649 | ||
| 33 | 479,601 -> 313,601 | ||
| 34 | 817,560 -> 817,862 | ||
| 35 | 135,272 -> 287,272 | ||
| 36 | 705,250 -> 796,159 | ||
| 37 | 457,656 -> 445,656 | ||
| 38 | 667,829 -> 659,829 | ||
| 39 | 804,450 -> 804,410 | ||
| 40 | 565,322 -> 565,113 | ||
| 41 | 645,614 -> 972,614 | ||
| 42 | 94,634 -> 421,634 | ||
| 43 | 739,903 -> 122,903 | ||
| 44 | 730,549 -> 963,782 | ||
| 45 | 798,563 -> 969,563 | ||
| 46 | 784,245 -> 176,245 | ||
| 47 | 439,872 -> 448,872 | ||
| 48 | 107,586 -> 906,586 | ||
| 49 | 33,162 -> 573,702 | ||
| 50 | 48,426 -> 362,112 | ||
| 51 | 927,662 -> 927,939 | ||
| 52 | 723,363 -> 723,389 | ||
| 53 | 321,237 -> 982,237 | ||
| 54 | 554,541 -> 554,726 | ||
| 55 | 779,292 -> 779,61 | ||
| 56 | 864,491 -> 864,970 | ||
| 57 | 497,482 -> 497,801 | ||
| 58 | 919,767 -> 919,965 | ||
| 59 | 57,611 -> 57,221 | ||
| 60 | 200,481 -> 200,229 | ||
| 61 | 164,292 -> 164,608 | ||
| 62 | 103,664 -> 694,73 | ||
| 63 | 950,162 -> 181,931 | ||
| 64 | 977,336 -> 293,336 | ||
| 65 | 946,912 -> 80,912 | ||
| 66 | 805,142 -> 89,858 | ||
| 67 | 976,85 -> 245,85 | ||
| 68 | 987,961 -> 987,530 | ||
| 69 | 783,683 -> 443,683 | ||
| 70 | 276,746 -> 490,532 | ||
| 71 | 424,352 -> 424,725 | ||
| 72 | 103,31 -> 559,31 | ||
| 73 | 697,284 -> 697,305 | ||
| 74 | 292,789 -> 627,454 | ||
| 75 | 61,83 -> 151,83 | ||
| 76 | 686,199 -> 652,233 | ||
| 77 | 780,883 -> 780,512 | ||
| 78 | 901,609 -> 346,54 | ||
| 79 | 136,939 -> 136,612 | ||
| 80 | 678,594 -> 408,594 | ||
| 81 | 987,693 -> 987,178 | ||
| 82 | 783,517 -> 828,517 | ||
| 83 | 718,846 -> 23,151 | ||
| 84 | 416,286 -> 518,286 | ||
| 85 | 480,612 -> 130,612 | ||
| 86 | 801,805 -> 801,259 | ||
| 87 | 676,749 -> 119,192 | ||
| 88 | 330,954 -> 936,348 | ||
| 89 | 258,407 -> 258,791 | ||
| 90 | 497,804 -> 668,804 | ||
| 91 | 330,723 -> 497,556 | ||
| 92 | 691,253 -> 691,408 | ||
| 93 | 141,68 -> 365,68 | ||
| 94 | 643,497 -> 305,159 | ||
| 95 | 498,938 -> 765,671 | ||
| 96 | 982,825 -> 580,825 | ||
| 97 | 863,300 -> 959,396 | ||
| 98 | 291,64 -> 291,745 | ||
| 99 | 601,609 -> 601,182 | ||
| 100 | 564,428 -> 564,66 | ||
| 101 | 792,365 -> 792,161 | ||
| 102 | 718,123 -> 718,813 | ||
| 103 | 545,493 -> 903,851 | ||
| 104 | 176,13 -> 988,825 | ||
| 105 | 514,205 -> 514,415 | ||
| 106 | 86,825 -> 446,825 | ||
| 107 | 684,867 -> 684,951 | ||
| 108 | 265,917 -> 936,246 | ||
| 109 | 310,655 -> 310,920 | ||
| 110 | 794,370 -> 809,370 | ||
| 111 | 170,475 -> 75,570 | ||
| 112 | 128,644 -> 200,572 | ||
| 113 | 293,105 -> 600,105 | ||
| 114 | 846,984 -> 976,984 | ||
| 115 | 531,311 -> 977,311 | ||
| 116 | 749,565 -> 315,565 | ||
| 117 | 892,311 -> 452,751 | ||
| 118 | 29,980 -> 974,35 | ||
| 119 | 433,355 -> 433,307 | ||
| 120 | 718,528 -> 261,985 | ||
| 121 | 649,488 -> 156,488 | ||
| 122 | 571,265 -> 119,717 | ||
| 123 | 801,31 -> 66,766 | ||
| 124 | 984,521 -> 213,521 | ||
| 125 | 553,973 -> 20,973 | ||
| 126 | 981,984 -> 15,18 | ||
| 127 | 174,117 -> 174,880 | ||
| 128 | 308,161 -> 308,443 | ||
| 129 | 342,633 -> 342,507 | ||
| 130 | 871,822 -> 258,822 | ||
| 131 | 899,835 -> 83,19 | ||
| 132 | 557,242 -> 557,211 | ||
| 133 | 163,57 -> 895,789 | ||
| 134 | 252,84 -> 342,174 | ||
| 135 | 863,512 -> 863,66 | ||
| 136 | 351,458 -> 351,304 | ||
| 137 | 548,427 -> 266,145 | ||
| 138 | 794,624 -> 794,303 | ||
| 139 | 408,889 -> 408,457 | ||
| 140 | 10,782 -> 10,216 | ||
| 141 | 837,230 -> 837,213 | ||
| 142 | 973,809 -> 109,809 | ||
| 143 | 913,53 -> 41,925 | ||
| 144 | 637,324 -> 921,40 | ||
| 145 | 806,603 -> 806,800 | ||
| 146 | 814,181 -> 41,954 | ||
| 147 | 320,790 -> 574,790 | ||
| 148 | 281,683 -> 646,683 | ||
| 149 | 145,344 -> 246,344 | ||
| 150 | 806,128 -> 806,164 | ||
| 151 | 677,855 -> 650,882 | ||
| 152 | 177,841 -> 177,25 | ||
| 153 | 775,254 -> 41,254 | ||
| 154 | 337,685 -> 563,459 | ||
| 155 | 69,271 -> 69,463 | ||
| 156 | 748,390 -> 504,634 | ||
| 157 | 370,203 -> 370,338 | ||
| 158 | 401,914 -> 436,879 | ||
| 159 | 562,139 -> 266,435 | ||
| 160 | 253,99 -> 232,99 | ||
| 161 | 238,270 -> 142,270 | ||
| 162 | 532,555 -> 433,555 | ||
| 163 | 219,23 -> 919,723 | ||
