Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,22 +1,21 @@
|
|||
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]]];
|
||||
instr = StringToStream[input],
|
||||
m[_] = 0;
|
||||
While[pp < Length@p,
|
||||
pp++;
|
||||
Switch[p[[pp]],
|
||||
">", mp++,
|
||||
"<", mp--,
|
||||
"+", m[mp]++,
|
||||
"-", m[mp]--,
|
||||
".", BinaryWrite[OutputStream["stdout", 1], 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];];
|
||||
bf[program_] := bf[program, ""]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue