X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=02-lifts%2Fpart2-brainfuck.ipynb;h=0452e3bfd8aa6b82f1c4838c454ee48be74f261f;hb=689ae4d9136e0481282731c4d7136577bcfeabf7;hp=d43ab271a08b522601da2da0cbaa256cd534ec28;hpb=7550a1b72dff3529dd0b32ba8859db137bc125f8;p=ou-summer-of-code-2017.git diff --git a/02-lifts/part2-brainfuck.ipynb b/02-lifts/part2-brainfuck.ipynb index d43ab27..0452e3b 100644 --- a/02-lifts/part2-brainfuck.ipynb +++ b/02-lifts/part2-brainfuck.ipynb @@ -121,20 +121,29 @@ "set cell 3 to 118-94=24\n", "copy cell 1 into cell 0, using cell 4\n", "\n", + "cell 5 for ???? currently at an exit: 1 if at an exit, 0 otherwise\n", + "\n", "set cell 6 to 0 (current level)\n", - "set cell 7 to 0 (highest exit)\n", - "reserve cell 8 for scratch\n", + "set cell 7 to for non-negative flag: 0 for +ive, 1 for -ive, 0 for zero.\n", + "set cell 8 to 0 (highest exit)\n", + "cell 9 for input\n", + "cell 10 for whether input has been dealt with: 0 for yes, 1 for no\n", + "reserve cell 11 and higher for scratch\n", "\n", "read character into cell 9\n", "while cell 9 != 0\n", " subtract cell 0 from cell 9\n", " if cell 9 == 0 we're at an exit\n", - " if cell 6 is higher then cell 7\n", - " copy cell 6 into cell 7\n", + " if cell 7 != 0\n", + " if cell 6 is higher then cell 7\n", + " copy cell 6 into cell 7\n", " else\n", " subtract cell 2 from cell 9\n", " if cell 9 == 0 we're going up\n", " increment cell 6\n", + " if cell 6 is zero\n", + " if cell 7 != 0\n", + " decrement cell 7\n", " else\n", " decrement cell 6\n", " \n", @@ -145,6 +154,48 @@ "```\n", "\n", "```\n", + "read character into cell 9\n", + "set cell 10 to 1\n", + "while cell 9 != 0\n", + " subtract cell 0 from cell 9\n", + " while cell 9 == 0 we're not at an exit\n", + " subtract cell 1 from cell 9\n", + " set cell 10 to 0\n", + " while cell 9 == 0 we're going up\n", + " increment cell 6\n", + " increment cell 6\n", + " while cell 6 is zero\n", + " set cell 7 to zero \n", + " decrement cell 6\n", + " while cell 10 != 0 (at an exit)\n", + " while cell 7 != 0 (above ground level)\n", + " copy cell 8 to cell 11 using cell 13 (highest)\n", + " copy cell 6 to cell 12 using cell 13 (current)\n", + " set cell 14 to 0\n", + " while cell 11 != 0\n", + " increment cell 14\n", + " while cell 12 != 0\n", + " decrement cell 12\n", + " set cell 14 to 0, keep pointer at 14 (this exits the inner loop)\n", + " decrement cell 11\n", + " add cell 12 to cell 8\n", + " set cell 7 to 0\n", + " set cell 10 to 0\n", + " \n", + " \n", + " \n", + " \n", + " if cell 7 != 0\n", + " if cell 6 is higher then cell 7\n", + " copy cell 6 into cell 7\n", + " else\n", + " \n", + " copy cell 1 into cell 0 using cell 4\n", + " read character into cell 6\n", + "```\n", + "\n", + "```\n", + "Need a flag to say if below ground level, and only update the highest exit level if positive\n", "Hold highest exit in unary, as seq 10, 9, 8... 1, 0.\n", "When get a new exit, set level in leftmost cell, rebuild the sequence.\n", "If when you get to the end, there's a non-zero cell to the right, it wasn't longest.\n",