summaryrefslogtreecommitdiffstats
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/__init__.py70
-rw-r--r--day1/example_part_1.txt4
-rw-r--r--day1/example_part_2.txt7
-rw-r--r--day1/input.txt1000
-rw-r--r--day1/test_init.py6
5 files changed, 1087 insertions, 0 deletions
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 -*-
2from abc import ABC
3from enum import Enum
4from typing import Iterator
5
6from aoc import BaseAssignment, I, T
7
8
9class 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
19class 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
26class 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 @@
11abc2
2pqr3stu8vwx
3a1b2c3d4e5f
4treb7uchet
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 @@
1two1nine
2eightwothree
3abcone2threexyz
4xtwone3four
54nineeightseven2
6zoneight234
77pqrstsixteen
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 @@
15ffour295
2m9qvkqlgfhtwo3seven4seven
32vdqng1sixzjlkjvq
45twonineeight3onefive
52three2seveneightseven
6eightsevenfive3bcptwo
7five8six
8twonineseven24one3
9one8bdxplbtfninefourspqn
10nineeight3fiveseven
11xmkhttr64htgvhjfivefcjlzjqrsjlfivekbcnhqpzg
12261flvsthree
13one2mgnphzcx45rmnffneight
14sevenfivesixzvpone8f1plj
15ccthpbg6six3
16f1hzds5kfdsj
17qkneightwofourninejzjfmkjv8eightthdtp
18eight62rvkjphrdtwoseventwo28
19eight33
20sevenkzvnkj5ftone
2176sixrcznjkthreethree72nf
225nnine
233cjseventhreen
24sixsix18ctxvtxbs
257mksmd9threetnkbtwo
267hxnrgnl8
27vq3dcgtlzgfives8kthone7
2876tmpjjvbzzclfour
29ptwonefive2threekfrtvnbmplpsevenseven
3079sixone
31mheightfhllpvk6rdnrznkndp
327sixfjsspxhljrtsz39szdtsrfkh
333prqtwolcljdhcksix6three3gjkvcsz
3431vjpsdqlncjone
352qhbsjcxqfive
36cccgsqgj2seveneight2
37eightthree65tbhvpnthree
38ltpeight27fivethxzjthree27
39m31cxstb4
40xfmnzconevzmzkcthree2
41837
42vjone779jzskrxqgkrd2
43rgd9eight
443onetwo34one
45threeffthlxtmc8zfpl7fivetwo2seven
46two6rxqghhnnthm
479gfjhhlc4hlpcc
48glcj9zdnfkrnfcvqqhr9four
49seven6564four
503lrlkmqbvllqpn7fivedmmqhk
518fivefiver3eighteight3
523eightthree
53bhzsjfivefour391753
54nine5sixsix4jrqdljfive8
55threeninenine68gkjlrh8n
567vdprdhrmbrnineonektjpseveneight
573prjtkg6three1
58nine5rnbxdsgdnine2seven
59threes6
6062zzbgfq7
615hbcvdhslxb
626msfzlhmksplcbmrqoneoneone
634sevennine3
64five99threezmxsj7sqbtthree
6556vbt42three
6612fjlcvkgcv
67dnsdbrphqhrthmqtm7sixonezv5fgtwo
685seven5fourlhgb
69fivetwo26threeone7eight3
70lxlzzhfkfive4eight2fivezqkdxczbmndvflrsq
7171nineseven5one58
72fivelncljrgtxkdq51gnnpvtsbnine3five
73mjlrpthgvz57skzbs24fourtwoneklr
74njqlhp39five
758xxmstonetwolhlcgzcpqb
768gjqlbgfive
77xcdssbrltmf8sevenkxntdzgfsv
78vhgjfxeightvfvpgcxsnineninepkrjtqtseven7
79two3ztllvnrmg7fivetwo
80five1jspfivethree1one
815stkpqcjhxvmrn
82three3six12fourkdmlgfbflm
837sixeightnnjnc4one7four
844bqszrqnfzl9nlp
85two3threesnjpncrjljpcxhjdzxqcjcjbktvxjgvnfp
8636tworrhlh
8743trbqvgrrsjbrxhk
88eight7five
89four934eight8three
909zjzhmtkt4bvljpttc25sixsix
91twotwocmzcczsjz2qcslmnjl1pqfjqfhlpmtjlpzpjhffxr
924fseven
93sevennvxlnineph8ninefqbm
942611five42
95two7nine
967eightfour7gh19
9771kzdvkfbqnineonetwo
98onesixnine325
995cbtbckx4vhtslbk
100eightdgczsgkc5seventlsfd
101xdljsnqjctzmmxcgxctdxxg73four
1022shjqglxct5rctbmgvfvjfvrqsvdmthree
103three71onekbksz8
104ninesevenzrcxnnbvninetwoftsvg39
105twofour36
106onerddzfgdnpkjxlbh9twojbtqk
107jjcnine59lgcttxncsix
108ninesevenone76zrtmvdponeprfszns
109bzrxtwocqczcmkdlnjtwor7
110sixjqcgcl973one5eight
111freightwo7three
112dnzdrnthreemlqvrjspl79kfkfrbjm6czkzqvqp
113two7953mftrgpkxjmrpvn
114xone4vqljzqrspsgdhvnsgsptwo4
1152612fvhthree
116one3nine
1178five9onetwo
118fourtwo45sixxkjgdvrpltlnrtdbbpjjmqq
119four1fiveonenine6
1204three4
121qkjpskjglpeightjnc8two
122eight85sixfour
12353fivefive
124lbmqqpdbpnppzzmttmbpkxbl6sixfour
125ninemlm7
126mbvxvl2
1271vpszgjvdbd
1287qd7two3onesevenkkgnnlztzxs
129cqrnn1ninefxpglvtkf1
1307sixvnknzqpnhvsix6tbfnljfoursixrjzqxctmq
131five889four
1325rvsk7tsljtfivefour
133prkhvq61clveight9dcvcfsr
134four6ninenp2
135xoneight2five3fqmc6zrgcbzbzghpvbzt
136sixghxgbjfivesxrth5frzxcjfivegnktshzrpmbdlp
1376prgnxdseven2ggcqhc88
138five46
1394bmvzlbcsggseventhreefivesix66
140pzkljhppcmpnnng4
141ninefivemqnjsmkgtnzzstrq55
142one4lveightqjhjjzmrtwo97sctp
1433vzdmk
144lrzj71215
145three78ddzzmvfxfzsqtkdqtfsnk5
146db7
147deightwofour9eight63foursixcgllm
148123
149sevenninegtphtjkkbhdx6sqbggcbljx4
1508qtk4
151thvml91nngfjgrsfive2three
15217nine92twojkvmfrmpqhtlk
153ninetworcvtjc76
1545jrzpvgchg7tlfdlbfmxj8stb
1553t6sixjtnjxhxnfv
1569f2skxmzgnthreenine
1578sevenonethreeeightsixthree
158csrcdmtmscqvqkpthreepfour86
159threeseveneightfour5zsgfour
160onellbgsvseven9
161rnnkxtbnx1threekbddbpzthreerxcnbcgx
162jbvlsxdxsixxjj65one5fours
163kzsix4zg8fgmzc
164mkfpflcpkd37