<?php
//$states = json_decode('[[[2,0,1],[1,1,0]],[[4,1],[3,0,1]]]');
$states = json_decode('[[[2,0,1],[1,1,0]],[[4,1,2],[3,0,1]],[[99,0],[99,0],[22,0],[33,1,2]]]');
$state = 0;
$tape = array(1, 1, 1, 1, 0, 0, 0);
if (substr(phpversion(), -5) == '-hhvm') {
$updatesInternalPointer = true;
$noticesPointerOnlyMutation = true;
$rightEdgeBug = false;
} elseif (substr(phpversion(), 0, 1) == 7) {
$updatesInternalPointer = false;
$noticesPointerOnlyMutation = true;
$rightEdgeBug = false;
} else {
$updatesInternalPointer = true;
$noticesPointerOnlyMutation = false;
$rightEdgeBug = true;
}
if ($rightEdgeBug) $tape[] = 0;
foreach ($tape as $k => &$v) {
if (is_null($state)) break;
@list ($v, $d, $state) = $states[$state][$v];
if ($d) {
if (count($tape) - $k < ($rightEdgeBug ? 3 : 2)) $tape[] = 0;
if (!$updatesInternalPointer) next($tape);
} elseif ($k) {
$lol = $tape;
if ($noticesPointerOnlyMutation) {
prev($tape);
if ($updatesInternalPointer) prev($tape);
} else {
prev($lol);
if ($updatesInternalPointer) prev($lol);
$tape = $lol;
}
unset($lol);
} else {
array_unshift($tape, 0);
if (!$updatesInternalPointer) {
$lol = $tape;
reset($tape);
unset($lol);
}
}
}
unset($v);
if ($rightEdgeBug) array_pop($tape);
var_dump($tape);
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.6
- array(8) {
[0]=>
int(4)
[1]=>
int(33)
[2]=>
int(33)
[3]=>
int(33)
[4]=>
int(33)
[5]=>
int(22)
[6]=>
int(0)
[7]=>
int(0)
}
preferences:
59.71 ms | 402 KiB | 37 Q