- https://www.codewars.com/kata/58817056e7a31c2ceb000052 Esolang: InfiniTick.
Started at 20:24 23.09.2020 Wednesday Sep.
Finished at 22:24 23.09.2020 Wednesday Sep. (2hrs 00minutes)
<?php | |
# https://www.codewars.com/kata/58817056e7a31c2ceb000052 Esolang: InfiniTick. | |
function interpreter(string $tape): string { | |
$x = str_split($tape); | |
$tape = ""; | |
foreach($x as $c) if(false != strpos("^+-&*<>/\\",$c)) $tape .= $c; | |
$key = 0; | |
$mem = [ | |
"0" => 0 | |
]; | |
$ans = ""; | |
while(true){ | |
$value = $tape[$i]; | |
if('>' === $value) $key += 1; | |
if("<" === $value) $key -= 1; | |
if(!isset($mem[strval($key)])) $mem[strval($key)] = 0; | |
if("+" === $value) $mem[strval($key)] += 1; | |
if("-" === $value) $mem[strval($key)] -= 1; | |
if(0 > $mem[strval($key)] ) $mem[strval($key)] = 255; | |
if(255 < $mem[strval($key)] ) $mem[strval($key)] = 0; | |
if("*" === $value) $ans .= chr($mem[strval($key)]); | |
if("&" === $value) break; | |
if(47 == ord($value) && 0 === $mem[strval($key)]) $i += 1; | |
if( 92 == ord($value) && 0 !== $mem[strval($key)]) $i += 1; | |
$i += 1; | |
$i = $i % strlen($tape); | |
} | |
return $ans; | |
} |
Started at 20:24 23.09.2020 Wednesday Sep.
Finished at 22:24 23.09.2020 Wednesday Sep. (2hrs 00minutes)