diff options
| author | 2023-12-03 13:46:27 +0100 | |
|---|---|---|
| committer | 2023-12-03 13:46:27 +0100 | |
| commit | d1bbbd066202b7e8a6ef75ef961de20ef4331a40 (patch) | |
| tree | 84f7459a6fd70966d1d22ea11a1c3251fcb20551 | |
| parent | 6794fc500be97c45c98fe39ed31d91cbc40dcd19 (diff) | |
| download | 2023-d1bbbd066202b7e8a6ef75ef961de20ef4331a40.tar.gz 2023-d1bbbd066202b7e8a6ef75ef961de20ef4331a40.tar.bz2 2023-d1bbbd066202b7e8a6ef75ef961de20ef4331a40.zip | |
WIP
| -rw-r--r-- | aoc/__main__.py | 2 | ||||
| -rw-r--r-- | day1/__init__.py | 70 | ||||
| -rw-r--r-- | day1/example_part_1.txt | 4 | ||||
| -rw-r--r-- | day1/example_part_2.txt | 7 | ||||
| -rw-r--r-- | day1/input.txt | 1000 | ||||
| -rw-r--r-- | day1/test_init.py | 6 |
6 files changed, 1088 insertions, 1 deletions
diff --git a/aoc/__main__.py b/aoc/__main__.py index 9bbaed9..f5f08d3 100644 --- a/aoc/__main__.py +++ b/aoc/__main__.py | |||
| @@ -17,7 +17,7 @@ class AssignmentPart(str, enum.Enum): | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | def day(assignment_part: str) -> str: | 19 | def day(assignment_part: str) -> str: |
| 20 | return assignment_part | 20 | return AssignmentPart(assignment_part).name |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | def kwargs(kwarg: str) -> List: | 23 | def kwargs(kwarg: str) -> List: |
diff --git a/day1/__init__.py b/day1/__init__.py new file mode 100644 index 0000000..ee66fd3 --- /dev/null +++ b/day1/__init__.py | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | from abc import ABC | ||
| 3 | from enum import Enum | ||
| 4 | from typing import Iterator | ||
| 5 | |||
| 6 | from aoc import BaseAssignment, I, T | ||
| 7 | |||
| 8 | |||
| 9 | class Assignment(BaseAssignment, ABC): | ||
| 10 | def run(self, input: Iterator[list[int]]) -> int: | ||
| 11 | input = list(input) | ||
| 12 | print(input) | ||
| 13 | return sum([ | ||
| 14 | int(f'{item[0]}{item[-1]}') | ||
| 15 | for item in input | ||
| 16 | ]) | ||
| 17 | |||
| 18 | |||
| 19 | class AssignmentOne(Assignment): | ||
| 20 | example_result = 142 | ||
| 21 | |||
| 22 | def parse_item(self, item: str) -> list[int]: | ||
| 23 | return [int(i) for i in item if i.isdigit()] | ||
| 24 | |||
| 25 | |||
| 26 | class AssignmentTwo(Assignment): | ||
| 27 | example_result = 281 | ||
| 28 | |||
| 29 | class Numbers(Enum): | ||
| 30 | one = 1 | ||
| 31 | two = 2 | ||
| 32 | three = 3 | ||
| 33 | four = 4 | ||
| 34 | five = 5 | ||
| 35 | six = 6 | ||
| 36 | seven = 7 | ||
| 37 | eight = 8 | ||
| 38 | nine = 9 | ||
| 39 | |||
| 40 | @staticmethod | ||
| 41 | def _parse_item(item: str): | ||
| 42 | numbers = { | ||
| 43 | index: number | ||
| 44 | for index, number in [ | ||
| 45 | (item.find(number.name), number.value) | ||
| 46 | for number in AssignmentTwo.Numbers | ||
| 47 | ] | ||
| 48 | if index >= 0 | ||
| 49 | } | ||
| 50 | |||
| 51 | for index, i in enumerate(item): | ||
| 52 | if i.isdigit(): | ||
| 53 | numbers[index] = int(i) | ||
| 54 | |||
| 55 | return [ | ||
| 56 | value | ||
| 57 | for key, value | ||
| 58 | in sorted( | ||
| 59 | numbers.items(), | ||
| 60 | key=lambda item: item[0] | ||
| 61 | ) | ||
| 62 | ] | ||
| 63 | |||
| 64 | def parse_item(self, item: str) -> list[int]: | ||
| 65 | return self._parse_item(item) | ||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | |||
diff --git a/day1/example_part_1.txt b/day1/example_part_1.txt new file mode 100644 index 0000000..7bbc69a --- /dev/null +++ b/day1/example_part_1.txt | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | 1abc2 | ||
| 2 | pqr3stu8vwx | ||
| 3 | a1b2c3d4e5f | ||
| 4 | treb7uchet | ||
diff --git a/day1/example_part_2.txt b/day1/example_part_2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/day1/example_part_2.txt | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | two1nine | ||
| 2 | eightwothree | ||
| 3 | abcone2threexyz | ||
| 4 | xtwone3four | ||
| 5 | 4nineeightseven2 | ||
| 6 | zoneight234 | ||
| 7 | 7pqrstsixteen | ||
diff --git a/day1/input.txt b/day1/input.txt new file mode 100644 index 0000000..c50fa2a --- /dev/null +++ b/day1/input.txt | |||
| @@ -0,0 +1,1000 @@ | |||
| 1 | 5ffour295 | ||
| 2 | m9qvkqlgfhtwo3seven4seven | ||
| 3 | 2vdqng1sixzjlkjvq | ||
| 4 | 5twonineeight3onefive | ||
| 5 | 2three2seveneightseven | ||
| 6 | eightsevenfive3bcptwo | ||
| 7 | five8six | ||
| 8 | twonineseven24one3 | ||
| 9 | one8bdxplbtfninefourspqn | ||
| 10 | nineeight3fiveseven | ||
| 11 | xmkhttr64htgvhjfivefcjlzjqrsjlfivekbcnhqpzg | ||
| 12 | 261flvsthree | ||
| 13 | one2mgnphzcx45rmnffneight | ||
| 14 | sevenfivesixzvpone8f1plj | ||
| 15 | ccthpbg6six3 | ||
| 16 | f1hzds5kfdsj | ||
| 17 | qkneightwofourninejzjfmkjv8eightthdtp | ||
| 18 | eight62rvkjphrdtwoseventwo28 | ||
| 19 | eight33 | ||
| 20 | sevenkzvnkj5ftone | ||
| 21 | 76sixrcznjkthreethree72nf | ||
| 22 | 5nnine | ||
| 23 | 3cjseventhreen | ||
| 24 | sixsix18ctxvtxbs | ||
| 25 | 7mksmd9threetnkbtwo | ||
| 26 | 7hxnrgnl8 | ||
| 27 | vq3dcgtlzgfives8kthone7 | ||
| 28 | 76tmpjjvbzzclfour | ||
| 29 | ptwonefive2threekfrtvnbmplpsevenseven | ||
| 30 | 79sixone | ||
| 31 | mheightfhllpvk6rdnrznkndp | ||
| 32 | 7sixfjsspxhljrtsz39szdtsrfkh | ||
| 33 | 3prqtwolcljdhcksix6three3gjkvcsz | ||
| 34 | 31vjpsdqlncjone | ||
| 35 | 2qhbsjcxqfive | ||
| 36 | cccgsqgj2seveneight2 | ||
| 37 | eightthree65tbhvpnthree | ||
| 38 | ltpeight27fivethxzjthree27 | ||
| 39 | m31cxstb4 | ||
| 40 | xfmnzconevzmzkcthree2 | ||
| 41 | 837 | ||
| 42 | vjone779jzskrxqgkrd2 | ||
| 43 | rgd9eight | ||
| 44 | 3onetwo34one | ||
| 45 | threeffthlxtmc8zfpl7fivetwo2seven | ||
| 46 | two6rxqghhnnthm | ||
| 47 | 9gfjhhlc4hlpcc | ||
| 48 | glcj9zdnfkrnfcvqqhr9four | ||
| 49 | seven6564four | ||
| 50 | 3lrlkmqbvllqpn7fivedmmqhk | ||
| 51 | 8fivefiver3eighteight3 | ||
| 52 | 3eightthree | ||
| 53 | bhzsjfivefour391753 | ||
| 54 | nine5sixsix4jrqdljfive8 | ||
| 55 | threeninenine68gkjlrh8n | ||
| 56 | 7vdprdhrmbrnineonektjpseveneight | ||
| 57 | 3prjtkg6three1 | ||
| 58 | nine5rnbxdsgdnine2seven | ||
| 59 | threes6 | ||
| 60 | 62zzbgfq7 | ||
| 61 | 5hbcvdhslxb | ||
| 62 | 6msfzlhmksplcbmrqoneoneone | ||
| 63 | 4sevennine3 | ||
| 64 | five99threezmxsj7sqbtthree | ||
| 65 | 56vbt42three | ||
| 66 | 12fjlcvkgcv | ||
| 67 | dnsdbrphqhrthmqtm7sixonezv5fgtwo | ||
| 68 | 5seven5fourlhgb | ||
| 69 | fivetwo26threeone7eight3 | ||
| 70 | lxlzzhfkfive4eight2fivezqkdxczbmndvflrsq | ||
| 71 | 71nineseven5one58 | ||
| 72 | fivelncljrgtxkdq51gnnpvtsbnine3five | ||
| 73 | mjlrpthgvz57skzbs24fourtwoneklr | ||
| 74 | njqlhp39five | ||
| 75 | 8xxmstonetwolhlcgzcpqb | ||
| 76 | 8gjqlbgfive | ||
| 77 | xcdssbrltmf8sevenkxntdzgfsv | ||
| 78 | vhgjfxeightvfvpgcxsnineninepkrjtqtseven7 | ||
| 79 | two3ztllvnrmg7fivetwo | ||
| 80 | five1jspfivethree1one | ||
| 81 | 5stkpqcjhxvmrn | ||
| 82 | three3six12fourkdmlgfbflm | ||
| 83 | 7sixeightnnjnc4one7four | ||
| 84 | 4bqszrqnfzl9nlp | ||
| 85 | two3threesnjpncrjljpcxhjdzxqcjcjbktvxjgvnfp | ||
| 86 | 36tworrhlh | ||
| 87 | 43trbqvgrrsjbrxhk | ||
| 88 | eight7five | ||
| 89 | four934eight8three | ||
| 90 | 9zjzhmtkt4bvljpttc25sixsix | ||
| 91 | twotwocmzcczsjz2qcslmnjl1pqfjqfhlpmtjlpzpjhffxr | ||
| 92 | 4fseven | ||
| 93 | sevennvxlnineph8ninefqbm | ||
| 94 | 2611five42 | ||
| 95 | two7nine | ||
| 96 | 7eightfour7gh19 | ||
| 97 | 71kzdvkfbqnineonetwo | ||
| 98 | onesixnine325 | ||
| 99 | 5cbtbckx4vhtslbk | ||
| 100 | eightdgczsgkc5seventlsfd | ||
| 101 | xdljsnqjctzmmxcgxctdxxg73four | ||
| 102 | 2shjqglxct5rctbmgvfvjfvrqsvdmthree | ||
| 103 | three71onekbksz8 | ||
| 104 | ninesevenzrcxnnbvninetwoftsvg39 | ||
| 105 | twofour36 | ||
| 106 | onerddzfgdnpkjxlbh9twojbtqk | ||
| 107 | jjcnine59lgcttxncsix | ||
| 108 | ninesevenone76zrtmvdponeprfszns | ||
| 109 | bzrxtwocqczcmkdlnjtwor7 | ||
| 110 | sixjqcgcl973one5eight | ||
| 111 | freightwo7three | ||
| 112 | dnzdrnthreemlqvrjspl79kfkfrbjm6czkzqvqp | ||
| 113 | two7953mftrgpkxjmrpvn | ||
| 114 | xone4vqljzqrspsgdhvnsgsptwo4 | ||
| 115 | 2612fvhthree | ||
| 116 | one3nine | ||
| 117 | 8five9onetwo | ||
| 118 | fourtwo45sixxkjgdvrpltlnrtdbbpjjmqq | ||
| 119 | four1fiveonenine6 | ||
| 120 | 4three4 | ||
| 121 | qkjpskjglpeightjnc8two | ||
| 122 | eight85sixfour | ||
| 123 | 53fivefive | ||
| 124 | lbmqqpdbpnppzzmttmbpkxbl6sixfour | ||
| 125 | ninemlm7 | ||
| 126 | mbvxvl2 | ||
| 127 | 1vpszgjvdbd | ||
| 128 | 7qd7two3onesevenkkgnnlztzxs | ||
| 129 | cqrnn1ninefxpglvtkf1 | ||
| 130 | 7sixvnknzqpnhvsix6tbfnljfoursixrjzqxctmq | ||
| 131 | five889four | ||
| 132 | 5rvsk7tsljtfivefour | ||
| 133 | prkhvq61clveight9dcvcfsr | ||
| 134 | four6ninenp2 | ||
| 135 | xoneight2five3fqmc6zrgcbzbzghpvbzt | ||
| 136 | sixghxgbjfivesxrth5frzxcjfivegnktshzrpmbdlp | ||
| 137 | 6prgnxdseven2ggcqhc88 | ||
| 138 | five46 | ||
| 139 | 4bmvzlbcsggseventhreefivesix66 | ||
| 140 | pzkljhppcmpnnng4 | ||
| 141 | ninefivemqnjsmkgtnzzstrq55 | ||
| 142 | one4lveightqjhj | ||
