Skip to content

Commit ec99a64

Browse files
committed
solve day 01 in python
1 parent aeb2085 commit ec99a64

File tree

7 files changed

+265
-15
lines changed

7 files changed

+265
-15
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ test:
77
test.example:
88
make test DAY=day-00-example
99

10-
test.01:
10+
test.day01:
1111
make test DAY=day-01
12-
test.02:
12+
test.day02:
1313
make test DAY=day-02
1414

1515
#
@@ -28,9 +28,9 @@ docker.test:
2828
docker.example:
2929
make docker.test DAY=day-00-example
3030

31-
docker.01:
31+
docker.day01:
3232
make docker.test DAY=day-01
33-
docker.02:
33+
docker.day02:
3434
make docker.test DAY=day-02
3535

3636
docker.all:

days/day-01/README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
# days/day-01
2-
## --- Part 1 ---
3-
## --- Part 2 ---
1+
# --- Day 1: Report Repair ---
2+
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+
24+
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.
25+
26+
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?
27+
28+
To play, please identify yourself via one of these services:
29+
30+
## --- Part Two ---
31+
32+
The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
33+
34+
Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
35+
36+
In your expense report, what is the product of the three entries that sum to 2020?

days/day-01/input.txt

Lines changed: 200 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,200 @@
1-
<insert input>
1+
1438
2+
781
3+
1917
4+
1371
5+
1336
6+
1802
7+
1566
8+
1878
9+
737
10+
1998
11+
1488
12+
1372
13+
1715
14+
1585
15+
1676
16+
1810
17+
1692
18+
1329
19+
1916
20+
1854
21+
1307
22+
1347
23+
1445
24+
1475
25+
1435
26+
1270
27+
1949
28+
1957
29+
1602
30+
1931
31+
1505
32+
1636
33+
1539
34+
1803
35+
1011
36+
1821
37+
1021
38+
1461
39+
1755
40+
1332
41+
1576
42+
1923
43+
1899
44+
1574
45+
1641
46+
1357
47+
1509
48+
1877
49+
1875
50+
1228
51+
1725
52+
1808
53+
1678
54+
1789
55+
1719
56+
1691
57+
1434
58+
1538
59+
2002
60+
1569
61+
1403
62+
1146
63+
1623
64+
1328
65+
1876
66+
520
67+
1930
68+
1633
69+
1990
70+
1330
71+
1402
72+
1880
73+
1984
74+
1938
75+
1898
76+
1908
77+
1661
78+
1335
79+
1424
80+
1833
81+
1731
82+
1568
83+
1659
84+
1554
85+
1323
86+
1344
87+
1999
88+
1716
89+
1851
90+
1313
91+
1531
92+
190
93+
1834
94+
1592
95+
1890
96+
1649
97+
1430
98+
1599
99+
869
100+
1460
101+
1009
102+
1771
103+
1818
104+
1853
105+
1544
106+
1279
107+
1997
108+
1896
109+
1272
110+
1772
111+
1375
112+
1373
113+
1689
114+
1249
115+
1840
116+
1528
117+
1749
118+
1364
119+
1670
120+
1361
121+
1408
122+
1828
123+
1864
124+
1826
125+
1499
126+
1507
127+
336
128+
1532
129+
1349
130+
1519
131+
1437
132+
1720
133+
1817
134+
1920
135+
1388
136+
1288
137+
1290
138+
1823
139+
1690
140+
1331
141+
1564
142+
1660
143+
1598
144+
1479
145+
1673
146+
1553
147+
1991
148+
66
149+
1571
150+
1453
151+
1398
152+
1814
153+
1679
154+
1652
155+
1687
156+
1951
157+
1334
158+
1319
159+
1605
160+
1757
161+
1517
162+
1724
163+
2008
164+
1601
165+
1909
166+
1286
167+
1780
168+
1901
169+
1961
170+
1798
171+
1628
172+
1831
173+
1277
174+
1297
175+
1744
176+
1946
177+
1407
178+
1856
179+
1922
180+
1476
181+
1836
182+
1240
183+
1591
184+
1572
185+
2000
186+
1813
187+
1695
188+
1723
189+
1238
190+
1588
191+
1881
192+
1850
193+
1298
194+
1411
195+
1496
196+
744
197+
1477
198+
1459
199+
1333
200+
1902

days/day-01/output.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<insert output>
1+
1020099
2+
49214880

days/day-01/solutions/day01.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
#-*- coding: utf-8 -*-
3+
4+
import fileinput
5+
6+
lines = [int(line) for line in fileinput.input()]
7+
8+
part1 = None
9+
part2 = None
10+
11+
for i in lines:
12+
for j in lines:
13+
if part1 is None and i + j == 2020:
14+
part1 = i*j
15+
16+
for k in lines:
17+
if part2 is None and i + j + k == 2020:
18+
part2 = i*j*k
19+
20+
print(part1)
21+
print(part2)

days/day-01/solutions/main.rs

Whitespace-only changes.

days/day-01/test.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
DIR=$(dirname $(realpath $0))
4+
D=$(dirname $(realpath $0))
55

6-
# Run tests
7-
# Example: $DIR/../../scripts/test-rust.sh $DIR ./solutions/main.rs
8-
9-
echo "$DIR / --- Empty --- ❌";
10-
exit 1337;
6+
$D/../../scripts/test-py.sh $D/input.txt $D/output.txt $D/solutions/day01.py

0 commit comments

Comments
 (0)