Day 21 and 22 part1 in both of them works part2 is something quite different.

This commit is contained in:
kplaczek
2021-12-22 20:20:44 +01:00
parent 8acd426a62
commit 7f136de3ef
8 changed files with 503 additions and 0 deletions

18
22/part1.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$array = [];
foreach ($input as $line) {
echo "$line\n";
preg_match('#(?P<status>on|off) x=(-?\d*)..(-?\d*),y=(-?\d*)..(-?\d*),z=(-?\d*)..(-?\d*)#', $line, $found);
for ($x = (int)$found[2]; $x <= (int)$found[3]; $x++) {
for ($y = (int)$found[4]; $y <= (int)$found[5]; $y++) {
for ($z = (int)$found[6]; $z <= (int)$found[7]; $z++) {
unset($array[$x . '|' . $y . '|' . $z]);
if ($found['status'] == 'on') {
$array[$x . '|' . $y . '|' . $z] = 1;
}
}
}
}
}
echo count($array); //644257