Last active
December 25, 2015 14:39
-
-
Save AlephAlpha/6993043 to your computer and use it in GitHub Desktop.
Brainfuck interpreter in Mathematica.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ToExpression[ | |
"input=StringToStream[\"" <> ##2 <> | |
"\"];Clear[memory];memory[_]=pointer=0;" <> | |
StringReplace[#, | |
{">" -> "pointer++;", | |
"<" -> "pointer--;", | |
"+" -> "memory[pointer]++;", | |
"-" -> "memory[pointer]--;", | |
"." -> "BinaryWrite[OutputStream[\"stdout\",1],memory[pointer]];", | |
"," -> "memory[pointer]=BinaryRead[input];", | |
"[" -> "While[memory[pointer]!=0,", | |
"]" -> "];", | |
_ -> ""}] <> | |
"Close[input];"] & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment