Skip to content

Commit 9f93792

Browse files
committed
Initial commit
0 parents  commit 9f93792

17 files changed

+902
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
config.php

2020/Day_01/benchmark.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"PHP": "9.2294192314148E-7 s"
3+
}

2020/Day_01/code.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../../lib/php/utils.php';
4+
5+
$input = readInput(__DIR__);
6+
7+
// Task code
8+
function part01(array $input): int
9+
{
10+
$result = 0;
11+
12+
foreach ($input as $firstValue) {
13+
foreach ($input as $secondValue) {
14+
$sum = $firstValue + $secondValue;
15+
if ($sum === 2020) {
16+
$result = $firstValue * $secondValue;
17+
}
18+
}
19+
}
20+
21+
return $result;
22+
}
23+
24+
function part02(array $input): int
25+
{
26+
$result = 0;
27+
28+
foreach ($input as $firstValue) {
29+
foreach ($input as $secondValue) {
30+
foreach ($input as $thirdValue) {
31+
$sum = $firstValue + $secondValue + $thirdValue;
32+
33+
if ($sum === 2020) {
34+
$result = $firstValue * $secondValue * $thirdValue;
35+
}
36+
}
37+
}
38+
}
39+
40+
return $result;
41+
}
42+
43+
// Execute
44+
calcExecutionTime();
45+
$result01 = part01($input);
46+
writeln('Solution Part 1: ' . $result01);
47+
$result02 = part02($input);
48+
writeln('Solution Part 2: ' . $result02);
49+
$executionTime = calcExecutionTime();
50+
51+
echo("Execution time: $executionTime" . PHP_EOL);
52+
saveBenchmarkTime($executionTime, __DIR__);
53+
54+
// Task test
55+
testResults(
56+
[935419, 49880012], // Expected
57+
[$result01, $result02], // Result
58+
);

2020/Day_01/description.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--- Day 1: Report Repair ---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.
2+
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.
3+
To save your vacation, you need to get all fifty stars by December 25th.
4+
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!
5+
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.
6+
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
7+
For example, suppose your expense report contained the following:
8+
1721
9+
979
10+
366
11+
299
12+
675
13+
1456
14+
15+
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.
16+
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?

2020/Day_01/input.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1883
2+
1543
3+
1801
4+
1731
5+
1070
6+
1631
7+
1490
8+
1179
9+
1098
10+
1582
11+
1717
12+
1830
13+
1408
14+
1524
15+
889
16+
985
17+
2005
18+
1540
19+
1085
20+
1607
21+
1518
22+
1993
23+
1496
24+
1537
25+
1514
26+
1719
27+
1218
28+
1420
29+
1027
30+
1339
31+
1430
32+
989
33+
1613
34+
1970
35+
1227
36+
1082
37+
1079
38+
1068
39+
1674
40+
1186
41+
1744
42+
1297
43+
1467
44+
1647
45+
1141
46+
1825
47+
1759
48+
1395
49+
1596
50+
1405
51+
1844
52+
1461
53+
1762
54+
1122
55+
1173
56+
1838
57+
1983
58+
1632
59+
1995
60+
1245
61+
1454
62+
1120
63+
1671
64+
1526
65+
1572
66+
1929
67+
1642
68+
1864
69+
1351
70+
1155
71+
1885
72+
1226
73+
1810
74+
1252
75+
1061
76+
1882
77+
2002
78+
1627
79+
1128
80+
1575
81+
1750
82+
1046
83+
1767
84+
1270
85+
1037
86+
1198
87+
1942
88+
1074
89+
1820
90+
1301
91+
1382
92+
1687
93+
1824
94+
1996
95+
1704
96+
1051
97+
1546
98+
1431
99+
1102
100+
1041
101+
1547
102+
1202
103+
1875
104+
1800
105+
1433
106+
1901
107+
1165
108+
1151
109+
1785
110+
1903
111+
1278
112+
1185
113+
1940
114+
1935
115+
1479
116+
1495
117+
719
118+
1683
119+
1972
120+
1483
121+
1589
122+
1636
123+
1055
124+
1317
125+
1530
126+
1990
127+
1099
128+
1697
129+
1286
130+
1089
131+
1136
132+
1383
133+
1802
134+
1618
135+
1050
136+
1980
137+
1279
138+
1777
139+
1635
140+
1721
141+
1660
142+
1569
143+
1554
144+
1432
145+
1695
146+
1551
147+
1601
148+
1263
149+
1866
150+
1998
151+
1466
152+
1205
153+
1445
154+
1578
155+
1267
156+
1873
157+
1610
158+
1900
159+
1192
160+
1827
161+
1305
162+
1528
163+
1140
164+
1440
165+
1269
166+
1748
167+
1187
168+
52
169+
1149
170+
1603
171+
1033
172+
1650
173+
1045
174+
1345
175+
1710
176+
1955
177+
1891
178+
1392
179+
1870
180+
1357
181+
1197
182+
1087
183+
1690
184+
1090
185+
622
186+
1590
187+
1304
188+
1533
189+
1971
190+
1959
191+
1842
192+
1172
193+
1653
194+
1093
195+
1299
196+
1203
197+
1119
198+
1193
199+
1223
200+
1291

2020/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Advent of Code 2020
2+
3+
[Advent of Code 2020](https://adventofcode.com/2020)
4+
5+
# Benchmarks
6+
7+
| Day | PHP |
8+
|:-------------:|:-------------:|
9+
| [Day 01](2020/Day_01/) | `9.2294192314148E-7 s` |
10+
| [Day 02](2020/Day_02/) | :x: |
11+
| [Day 03](2020/Day_03/) | :x: |
12+
| [Day 04](2020/Day_04/) | :x: |
13+
| [Day 05](2020/Day_05/) | :x: |
14+
| [Day 06](2020/Day_06/) | :x: |
15+
| [Day 07](2020/Day_07/) | :x: |
16+
| [Day 08](2020/Day_08/) | :x: |
17+
| [Day 09](2020/Day_09/) | :x: |
18+
| [Day 10](2020/Day_10/) | :x: |
19+
| [Day 11](2020/Day_11/) | :x: |
20+
| [Day 12](2020/Day_12/) | :x: |
21+
| [Day 13](2020/Day_13/) | :x: |
22+
| [Day 14](2020/Day_14/) | :x: |
23+
| [Day 15](2020/Day_15/) | :x: |
24+
| [Day 16](2020/Day_16/) | :x: |
25+
| [Day 17](2020/Day_17/) | :x: |
26+
| [Day 18](2020/Day_18/) | :x: |
27+
| [Day 19](2020/Day_19/) | :x: |
28+
| [Day 20](2020/Day_20/) | :x: |
29+
| [Day 21](2020/Day_21/) | :x: |
30+
| [Day 22](2020/Day_22/) | :x: |
31+
| [Day 23](2020/Day_23/) | :x: |
32+
| [Day 24](2020/Day_24/) | :x: |
33+
| [Day 25](2020/Day_25/) | :x: |

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Advent of Code
2+
3+
[2015](/2015/README.md) | [2016](/2016/README.md) | [2017](/2017/README.md) |
4+
[2018](/2018/README.md) | [2019](/2020/README.md) | [2020](/2020/README.md)
5+
6+
This repository contains my solutions for [Advent of Code](https://adventofcode.com/).
7+
8+
The folder for each day contains:
9+
- Task of the day
10+
- Input for the given task
11+
- Code to solve the given task
12+
- My solutions to the given input
13+
14+
## Requirements
15+
16+
- PHP 7.4
17+
- Advent of Code account
18+
19+
## Installation
20+
21+
- `cp config.php.example config.php`
22+
- Put your session token under: `config.php` file to be able to download descriptions and inputs.
23+
24+
## Usage
25+
26+
- `bin/task --year 2020 --day 1` - will prepare everything for the given task.
27+
- `bin/run --year 2020 --day 1` - will execute all `code.*` files for the given task.
28+
- `bin/readme --year 2020` - will create a `README.md` for the given year.
29+
30+
### Languages
31+
32+
You can add every language you want use.
33+
You only need to add the binary for executing your script into `binary-ext.map.php`.
34+
35+
Already added languages:
36+
- PHP
37+
- Javascript/Node

0 commit comments

Comments
 (0)