it's an interpreter (by me) of brainf*uck code.
(brainf*uck is an esoteric programming languages)
Code:<?php
function brainfuck($code){
$out = '';
for($a=array(),$p=0,$l=array(),$i=0; $i<strlen($code); $i++){
if(!$code[$i]) continue;
switch($code[$i]){
case '>': $p++;
break;
case '<': $p--;
break;
case '+': $a[$p]++;
break;
case '-': $a[$p]--;
break;
case '[': $l[] = $i;
break;
case ']': if($a[$p]>0)
$i=$l[sizeof($l)-1];
else
array_pop($l);
break;
case ',': $c = trim(fgets(STDIN));
$a[$p] = ord($c[0]);
break;
case '.': $out.=chr($a[$p]);
break;
}
}
return $out;
}
print brainfuck(">+++++++[<+++++++++>-]<+++.>+++++[<++++++++++>-]<--.>+++++[<--->-]<--.
++++++++.+++++.>++++[<---------->-]<.>+++++[<++++++++++>-]<---.>+++[<------>-]<.
++++++++.>+++++[<--------------->-]<.>++++[<++++++++++>-]<+.
>++++++++[<+++++>-]<---.++++++.>+++++[<--->-]<.>++++++[<++>-]<+.
--.++.>++++++[<-->-]<-.>++++++[<++>-]<+++.>++++++[<-->-]<---.
>++++++[<++>-]<+.>++++++++[<---------->-]<--.>+++++++[<++++++++++>-]<+++.
+++++.>++++++++[<---------->-]<++.>+++++[<+++++++++>-]<+++.
>+++[<--->-]<+.>+++[<+++>-]<-.[-]++++++++++.");
?>bash-3.2$ time php brainfuck.php
BrainFuck Interpreter in PHP
real 0m0.032s
user 0m0.021s
sys 0m0.009s
Moved to the code section. First interpreter I've seen in PHP. Thanks for the share!
What is this ment to do?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
OK I will later, I see the results but what does it actually do?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
What do you mean...it runs brainfuck code....its essentially a language with only pointer functions and stdin/stdout...
Oh. If someone said that brainfuck was a language, I would of understood![]()
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks