Day 21 and 22 part1 in both of them works part2 is something quite different.
This commit is contained in:
18
22/part1.php
Normal file
18
22/part1.php
Normal 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
|
||||
Reference in New Issue
Block a user