From e87288e9e5b3903773574b9244822c618a107e6e Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 16 Jun 2017 08:39:57 +0100 Subject: [PATCH] Working on Brainfuck solutions --- 02-lifts/part1-brainfuck.ipynb | 4 +-- 02-lifts/part2-brainfuck.ipynb | 59 +++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/02-lifts/part1-brainfuck.ipynb b/02-lifts/part1-brainfuck.ipynb index bc880de..608180d 100644 --- a/02-lifts/part1-brainfuck.ipynb +++ b/02-lifts/part1-brainfuck.ipynb @@ -292,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 200, "metadata": {}, "outputs": [ { @@ -301,7 +301,7 @@ "([94, 94, 24, 0, 3, 0], 255, 5)" ] }, - "execution_count": 197, + "execution_count": 200, "metadata": {}, "output_type": "execute_result" } 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", -- 2.34.1