3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on kNkVO
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.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) }