Skip to content

Commit 08d48df

Browse files
committed
Solved 2020 day 1
1 parent 05b74f6 commit 08d48df

File tree

4 files changed

+288
-0
lines changed

4 files changed

+288
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.
4+
Surely, Christmas will go on without you.
5+
6+
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a
7+
starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow,
8+
you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
9+
10+
To save your vacation, you need to get all fifty stars by December 25th.
11+
12+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second
13+
puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
14+
15+
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently,
16+
something isn't quite adding up.
17+
18+
Specifically, they need you to find the two entries that sum to ```2020``` and then multiply those two numbers together.
19+
20+
For example, suppose your expense report contained the following:
21+
22+
```
23+
1721
24+
979
25+
366
26+
299
27+
675
28+
1456
29+
```
30+
31+
In this list, the two entries that sum to ```2020``` are ```1721``` and ```299```. Multiplying them together
32+
produces ```1721 * 299 = 514579```, so the correct answer is ```514579```.
33+
34+
Of course, your expense report is much larger. Find the two entries that sum to ```2020```; what do you get if you
35+
multiply them together?
36+
37+
### --- Part Two ---
38+
39+
The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from
40+
a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same
41+
criteria.
42+
43+
Using the above example again, the three entries that sum to ```2020``` are ```979```, ```366```, and ```675```.
44+
Multiplying them together produces the answer, ```241861950```.
45+
46+
In your expense report, what is the product of the three entries that sum to ```2020```?
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\AdventSolutions\Year2020\Day1;
4+
5+
use App\AdventSolutions\AbstractSolution;
6+
7+
class Solution2020Day1 extends AbstractSolution
8+
{
9+
public function solvePart1($input): string
10+
{
11+
foreach ($input as $value) {
12+
foreach ($input as $value2) {
13+
if ($value + $value2 === 2020) {
14+
return $value * $value2;
15+
}
16+
}
17+
}
18+
19+
return "No solution found!";
20+
}
21+
22+
public function solvePart2($input): string
23+
{
24+
foreach ($input as $value) {
25+
foreach ($input as $value2) {
26+
foreach ($input as $value3) {
27+
if ($value + $value2 + $value3 === 2020) {
28+
return $value * $value2 * $value3;
29+
}
30+
}
31+
}
32+
}
33+
34+
return "No solution found!";
35+
}
36+
}
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1941
2+
1887
3+
1851
4+
1874
5+
1612
6+
1960
7+
1971
8+
1983
9+
1406
10+
1966
11+
1554
12+
1892
13+
1898
14+
1926
15+
1081
16+
1992
17+
1073
18+
1603
19+
177
20+
1747
21+
1063
22+
1969
23+
1659
24+
1303
25+
1759
26+
1853
27+
1107
28+
1818
29+
1672
30+
1352
31+
2002
32+
1838
33+
1985
34+
1860
35+
1141
36+
1903
37+
1334
38+
1489
39+
1178
40+
1823
41+
1499
42+
1951
43+
1225
44+
1503
45+
1417
46+
1724
47+
1165
48+
1339
49+
1816
50+
1504
51+
1588
52+
1997
53+
1946
54+
1324
55+
1771
56+
1982
57+
1272
58+
1367
59+
1439
60+
1252
61+
1902
62+
1940
63+
1333
64+
1750
65+
1512
66+
1538
67+
1168
68+
2001
69+
1797
70+
1233
71+
972
72+
1306
73+
1835
74+
1825
75+
1822
76+
1880
77+
1732
78+
1785
79+
1727
80+
1275
81+
1355
82+
1793
83+
1485
84+
1297
85+
1932
86+
1519
87+
1587
88+
1382
89+
1914
90+
1745
91+
1087
92+
1996
93+
1746
94+
1962
95+
1573
96+
2008
97+
1868
98+
1278
99+
1386
100+
1238
101+
1242
102+
1170
103+
1476
104+
1161
105+
1754
106+
1807
107+
1514
108+
1189
109+
1916
110+
1884
111+
1535
112+
1217
113+
1911
114+
1861
115+
1493
116+
1409
117+
1783
118+
1222
119+
1955
120+
1673
121+
1502
122+
607
123+
2010
124+
1846
125+
1819
126+
1500
127+
1799
128+
1475
129+
1146
130+
1608
131+
1806
132+
1660
133+
1618
134+
1904
135+
978
136+
1762
137+
1925
138+
1185
139+
1154
140+
1239
141+
1843
142+
1986
143+
533
144+
1509
145+
1913
146+
287
147+
1707
148+
1115
149+
1699
150+
1859
151+
1077
152+
1915
153+
1412
154+
1360
155+
1646
156+
1973
157+
1627
158+
1755
159+
1748
160+
1769
161+
1886
162+
1422
163+
1686
164+
950
165+
100
166+
1372
167+
1068
168+
1370
169+
1428
170+
1870
171+
1108
172+
190
173+
1891
174+
1794
175+
1228
176+
1128
177+
1365
178+
1740
179+
1888
180+
1460
181+
1758
182+
1906
183+
1917
184+
1989
185+
1251
186+
1866
187+
1560
188+
1921
189+
1777
190+
1102
191+
1850
192+
1498
193+
683
194+
1840
195+
1800
196+
1112
197+
1908
198+
1442
199+
1082
200+
1071
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1721
2+
979
3+
366
4+
299
5+
675
6+
1456

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy