Files
advent_of_code_2021/22/part1.php

18 lines
683 B
PHP

<?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