Skip to content

Commit c0b60a9

Browse files
Complete Day 1. Part 1
1 parent af27541 commit c0b60a9

File tree

5 files changed

+252
-0
lines changed

5 files changed

+252
-0
lines changed

day1/README.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PART 1.
2+
--- Day 1: Report Repair ---
3+
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.
4+
5+
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
6+
7+
To save your vacation, you need to get all fifty stars by December 25th.
8+
9+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
10+
11+
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.
12+
13+
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
14+
15+
For example, suppose your expense report contained the following:
16+
17+
1721
18+
979
19+
366
20+
299
21+
675
22+
1456
23+
In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579.
24+
25+
Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?

day1/__init__.py

Whitespace-only changes.

day1/expense_report.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def calculate(expenses: list, magic_number: int) -> int:
2+
for i, first in enumerate(expenses):
3+
for j, second in enumerate(expenses[i + 1:]):
4+
if first + second == magic_number:
5+
return first * second
6+
7+
8+
if __name__ == '__main__':
9+
with open('input.txt') as data:
10+
expenses = [int(expense) for expense in data.read().splitlines()]
11+
print(calculate(expenses, 2020))

day1/input.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1587
2+
1407
3+
1717
4+
1596
5+
1566
6+
1752
7+
1925
8+
1847
9+
1716
10+
1726
11+
1611
12+
1628
13+
1853
14+
1864
15+
1831
16+
1942
17+
1634
18+
1964
19+
1603
20+
1676
21+
1256
22+
1906
23+
1655
24+
1790
25+
1666
26+
1470
27+
1540
28+
1544
29+
1100
30+
1447
31+
1384
32+
1464
33+
1651
34+
1572
35+
907
36+
1653
37+
1265
38+
1510
39+
1639
40+
1818
41+
376
42+
1378
43+
1132
44+
1750
45+
1491
46+
1788
47+
1882
48+
1779
49+
1640
50+
1586
51+
1525
52+
1458
53+
1994
54+
1782
55+
1412
56+
1033
57+
1416
58+
1813
59+
1520
60+
1968
61+
715
62+
1396
63+
1745
64+
1506
65+
1024
66+
1798
67+
1870
68+
1615
69+
1957
70+
1718
71+
1349
72+
1983
73+
1387
74+
1738
75+
1588
76+
1321
77+
1160
78+
1907
79+
1861
80+
1940
81+
1475
82+
2004
83+
1852
84+
1760
85+
1608
86+
1028
87+
1820
88+
1495
89+
1811
90+
1737
91+
1417
92+
1316
93+
1087
94+
1803
95+
1595
96+
1346
97+
1971
98+
1692
99+
1678
100+
1330
101+
1480
102+
1097
103+
1898
104+
1973
105+
1567
106+
1733
107+
1336
108+
1381
109+
1327
110+
1670
111+
1436
112+
1989
113+
1334
114+
89
115+
1862
116+
1715
117+
1743
118+
1967
119+
1765
120+
1402
121+
1729
122+
1749
123+
1671
124+
1196
125+
1650
126+
1089
127+
1814
128+
1783
129+
1225
130+
1823
131+
1746
132+
2009
133+
1886
134+
1748
135+
1481
136+
1739
137+
1912
138+
1663
139+
1668
140+
1314
141+
1594
142+
705
143+
1449
144+
1731
145+
1487
146+
1648
147+
1466
148+
1317
149+
1979
150+
1799
151+
1926
152+
1703
153+
1656
154+
1978
155+
2005
156+
1865
157+
1982
158+
1951
159+
1892
160+
1713
161+
1744
162+
1598
163+
1606
164+
1583
165+
1895
166+
1804
167+
1430
168+
1816
169+
1364
170+
1575
171+
1918
172+
1431
173+
1812
174+
1471
175+
1797
176+
928
177+
1934
178+
1156
179+
94
180+
1563
181+
1909
182+
1453
183+
1392
184+
1427
185+
1819
186+
1524
187+
1695
188+
1866
189+
2008
190+
1413
191+
1698
192+
1051
193+
1707
194+
1904
195+
1681
196+
1541
197+
1621
198+
1421
199+
1809
200+
1576

day1/test_expense_report.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
3+
from day1 import expense_report
4+
5+
6+
class MyTestCase(unittest.TestCase):
7+
def test_something(self):
8+
expenses = [1721, 979, 366, 299, 675, 1456]
9+
expected = 514579
10+
answer = expense_report.calculate(expenses, 2020)
11+
12+
13+
14+
15+
if __name__ == '__main__':
16+
unittest.main()

0 commit comments

Comments
 (0)