Skip to content

Commit 2ac9941

Browse files
committed
2020: Day 1
1 parent 7d92fd1 commit 2ac9941

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed

2020/01/input.txt

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1337
2+
1906
3+
2007
4+
1939
5+
818
6+
1556
7+
2005
8+
1722
9+
1484
10+
1381
11+
1682
12+
1253
13+
1967
14+
1718
15+
2002
16+
1398
17+
1439
18+
1689
19+
1746
20+
1979
21+
1985
22+
1387
23+
1509
24+
1566
25+
1276
26+
1625
27+
1853
28+
882
29+
1750
30+
1390
31+
1731
32+
1555
33+
1860
34+
1675
35+
1457
36+
1554
37+
1506
38+
1639
39+
1543
40+
1849
41+
1062
42+
1869
43+
1769
44+
1858
45+
1916
46+
1504
47+
1747
48+
1925
49+
1275
50+
1273
51+
1383
52+
1816
53+
1814
54+
1481
55+
1649
56+
1993
57+
1759
58+
1949
59+
1499
60+
1374
61+
1613
62+
1424
63+
783
64+
1765
65+
1576
66+
1933
67+
1270
68+
1844
69+
1856
70+
1634
71+
1261
72+
1293
73+
1741
74+
668
75+
1573
76+
1599
77+
1877
78+
1474
79+
1918
80+
476
81+
1515
82+
1029
83+
202
84+
1589
85+
1867
86+
1503
87+
1582
88+
1605
89+
1557
90+
587
91+
1462
92+
1955
93+
1806
94+
1834
95+
1739
96+
1343
97+
1594
98+
1622
99+
1972
100+
1527
101+
1798
102+
1719
103+
1866
104+
134
105+
2000
106+
1992
107+
1966
108+
1909
109+
1340
110+
1621
111+
1921
112+
1256
113+
1365
114+
1314
115+
1748
116+
1963
117+
1379
118+
1627
119+
1848
120+
1977
121+
1917
122+
1826
123+
1716
124+
1631
125+
1404
126+
1936
127+
1677
128+
1661
129+
1986
130+
1997
131+
1603
132+
1932
133+
1780
134+
1902
135+
2009
136+
1257
137+
1871
138+
1362
139+
1662
140+
1507
141+
1255
142+
1539
143+
1962
144+
1886
145+
1513
146+
1264
147+
1873
148+
1700
149+
807
150+
1426
151+
1697
152+
1698
153+
1519
154+
1791
155+
1240
156+
1542
157+
1497
158+
1761
159+
1640
160+
1502
161+
1770
162+
1437
163+
1333
164+
1805
165+
1591
166+
1644
167+
1420
168+
1809
169+
1587
170+
1421
171+
1540
172+
1942
173+
470
174+
1940
175+
1831
176+
1247
177+
1632
178+
1975
179+
1774
180+
1919
181+
1829
182+
1944
183+
1553
184+
1361
185+
1483
186+
1995
187+
1868
188+
1601
189+
1552
190+
1854
191+
1490
192+
1855
193+
1987
194+
1538
195+
1389
196+
1454
197+
1427
198+
1686
199+
1456
200+
1974

2020/01/main.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Day01:
2+
3+
def __init__(self):
4+
self.puzzle_input = self.load_input()
5+
6+
def part_one(self) -> int:
7+
num_set = set()
8+
for first in self.puzzle_input:
9+
second = 2020 - first
10+
if second in num_set:
11+
return first * second
12+
num_set.add(first)
13+
14+
def part_two(self) -> int:
15+
for first in self.puzzle_input:
16+
num_to_find = 2020 - first
17+
num_set = set()
18+
for second in self.puzzle_input:
19+
third = num_to_find - second
20+
if third in num_set:
21+
return first * second * third
22+
num_set.add(second)
23+
24+
@staticmethod
25+
def load_input() -> list:
26+
list_input = []
27+
with open("input.txt") as file:
28+
for line in file:
29+
list_input.append(int(line.rstrip()))
30+
return list_input
31+
32+
33+
day = Day01()
34+
print(f'Result part 1: {day.part_one()}')
35+
print(f'Result part 2: {day.part_two()}')

0 commit comments

Comments
 (0)