Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active October 12, 2020 20:17
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/0ee4650bd493e6fecd14dc8f2c32681a to your computer and use it in GitHub Desktop.
Save lbvf50mobile/0ee4650bd493e6fecd14dc8f2c32681a to your computer and use it in GitHub Desktop.
Just PHP FUN 126.
<?php
# https://www.codewars.com/kata/587edac2bdf76ea23500011a Esolang: Tick.
function interpreter(string $tape): string {
$i = 0; $ans = "";
$mem = [];
for($j=0; $j < strlen($tape); $j += 1){
$c = $tape[$j];
if('>' == $c){
$i += 1;
if(false === isset($mem[$i])) $mem[$i] == 0;
}
if('<' == $c){
$i -= 1;
if( false === isset($mem[$i])) $mem[$i] == 0;
}
if( '+' == $c){
$mem[$i] += 1;
$mem[$i] %= 256;
}
if( '*' == $c) $ans .= chr($mem[$i]);
}
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment