-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.php
58 lines (43 loc) · 1.3 KB
/
Day1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace XonneX\AdventOfCode\Y2020\Solutions\Day1;
use RuntimeException;
use XonneX\AdventOfCode\Core\AbstractSolution;
class Day1 extends AbstractSolution
{
public function __construct()
{
parent::__construct(2020, 1);
}
protected function partOne(string $input): string
{
$parts = explode("\n", $input);
foreach ($parts as $part1) {
$part1 = (int) $part1;
foreach ($parts as $part2) {
$part2 = (int) $part2;
if ($part1 + $part2 === 2020) {
return (string) ($part1 * $part2);
}
}
}
throw new RuntimeException('Not working');
}
protected function partTwo(string $input): string
{
$parts = explode("\n", $input);
foreach ($parts as $part1) {
$part1 = (int) $part1;
foreach ($parts as $part2) {
$part2 = (int) $part2;
foreach ($parts as $part3) {
$part3 = (int) $part3;
if ($part1 + $part2 + $part3 === 2020) {
return (string) ($part1 * $part2 * $part3);
}
}
}
}
throw new RuntimeException('Not working');
}
}