<?php
//$fast = true;
if (isset($fast)) {$fil = "input-fast.txt";echo "Eksempel aktiv\n";} else $fil = "input-full.txt";
$linjer = file($fil, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
function parse($linje) {
$step0 = substr($linje,0,7);
$range = range(0,127);
foreach (str_split($step0) as $char) {
$step1 = array_chunk($range, count($range)/2, true);
if ($char == "F") { // Front
$range = $step1[0];
} else {
$range = $step1[1];
}
}
$row = $range;
$step2 = substr($linje,-3);
$range = range(0,7);
foreach (str_split($step2) as $char) {
$step2 = array_chunk($range, count($range)/2, true);
if ($char == "L") {
$range = $step2[0];
} else {
$range = $step2[1];
}
}
$column = $range;
return ((array_sum($row) * 8) + array_sum($column));
}
$seter = range(0,1000);
foreach ($linjer as $linje) {
$tall = parse($linje);
unset($seter[$tall]);
}
for ($i=1;$i<=999;$i++) {
if (isset($seter[$i]) AND !isset($seter[$i-1]) AND !isset($seter[$i+1])) echo "Ditt sete: ".$seter[$i]."\n";
}