add brainf*** stuff
This commit is contained in:
parent
ca9df1a6be
commit
202646288c
34 changed files with 812 additions and 2666 deletions
22
Task/Execute-Brain----/Mathematica/execute-brain-----1.math
Normal file
22
Task/Execute-Brain----/Mathematica/execute-brain-----1.math
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
bf[program_, input_] :=
|
||||
Module[{p = Characters[program], pp = 0, m, mp = 0, bc = 0,
|
||||
instr = StringToStream[input],
|
||||
outstr = OpenWrite[BinaryFormat -> True]},
|
||||
m[_] = 0;
|
||||
While[pp < Length@p,
|
||||
pp++;
|
||||
Switch[p[[pp]],
|
||||
">", mp++,
|
||||
"<", mp--,
|
||||
"+", m[mp]++,
|
||||
"-", m[mp]--,
|
||||
".", BinaryWrite[outstr, m[mp]],
|
||||
",", m[mp] = BinaryRead[instr],
|
||||
"[", If[m[mp] == 0,
|
||||
bc = 1;
|
||||
While[bc > 0, pp++; Switch[p[[pp]], "[", bc++, "]", bc--]]],
|
||||
"]", If[m[mp] != 0,
|
||||
bc = -1;
|
||||
While[bc < 0, pp--; Switch[p[[pp]], "[", bc++, "]", bc--]]]]];
|
||||
Close[instr]; FilePrint[Close[outstr]]];
|
||||
bf[program_] := bf[program, ""]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
bf["++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.
|
||||
<<+++++++++++++++.>.+++.------.--------.>+.>."]
|
||||
Loading…
Add table
Add a link
Reference in a new issue