Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 23, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/e7617dcda1d3d0a853d86ba581d8085a to your computer and use it in GitHub Desktop.
Save lbvf50mobile/e7617dcda1d3d0a853d86ba581d8085a to your computer and use it in GitHub Desktop.
Just PHP FUN 110.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment