Closed Zomis closed 8 years ago
See https://github.com/Zomis/BrainDuck/commit/b5ee5ecaee01a41697b408821e8ba89aa1cc151c and a couple of parent commits for optimizations and the reasoning behind them
About >>-<+>
which can become simply >+>-
:
Reset the check after each [ ] . ,
, when one of those characters come up, analyse the recent > < + -
characters and see if the effect caused by those characters can be achieved in a better way.
For example, >>-<+>
results in the integer array [ 0, 1, -1 ]
and the offset 2
(meaning that we have moved 2 steps to the right after the sequence has been performed). The shortest way to accomplish the same integer array is clearly to do >+>-
.
The reason to not include [ ]
in the check is because that is a conditional check, and needs a loop-analyse before any conclusions can be drawn about whether or not it will always be performed a specific number of times or not. Possibly include those in the analyse at a later time.
First of all, remember that the only thing that can change a Brainfuck program behavior is user-input, with the
,
Brainfuck command.[x] Avoid taking unnecessary turns, for example:
which equals to
>>-<+>
can become simply>+>-
Optimize some things for speed (number of instructions being performed when running), optimize some things for code compactness.