-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.php
More file actions
30 lines (24 loc) · 814 Bytes
/
day1.php
File metadata and controls
30 lines (24 loc) · 814 Bytes
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
<?php
$array = file('day1.txt');
$solution1 = null;
foreach ($array as $firstKey => $firstValue) {
if ($solution1) { continue; }
foreach ($array as $secondKey => $secondValue) {
if (($firstValue + $secondValue == 2020) && ($firstKey != $secondKey)) { $solution1 = $firstValue * $secondValue; }
}
}
echo("$solution1\n");
$solution2 = null;
foreach ($array as $firstKey => $firstValue) {
if ($solution2) { continue; }
foreach ($array as $secondKey => $secondValue) {
foreach ($array as $thirdKey => $thirdValue) {
if (($firstValue + $secondValue + $thirdValue == 2020) &&
($firstKey != $secondKey) &&
($thirdKey != $secondKey) && ($thirdKey != $firstKey)) {
$solution2 = $firstValue * $secondValue * $thirdValue;
}
}
}
}
echo("$solution2\n");