Is there an efficient algorithm that determine the sum of two numbers, even if these numbers are greater than ten?
Adding numbers whose sum is greater than 10 in brainfuck
312 views Asked by george At
2
There are 2 answers
0
On
Using http://fatiherikli.github.io/brainfuck-visualizer/ you can see the value of each cell numerically, not having to use all that dumb ASCII conversion stuff. Then, just program in your inputs and the algorithm.
++++++>+++++ 6 plus 5
[<+>-]
Adds one to 6 and subtracts one from 5 each iteration, making 11. The visualizer will show that the cell is 11. If you want to preserve the y value, add a "temp" cell
++++++>+++++>[-] #0: 6 #1: 5 #2: 0
<[<+>>+<-]
>[<+>-]
the user can only enter the numbers one digit at a time. Assuming only positive numbers can be entered the algorithm to parse it is as follows.
You will need to handle when the user enters the enter key to finish entering the number, and the above algorithm only works for numbers up to 255 (assuming 8 bit cells).
From then on you have a cell with a number. Do this again to get a cell with another number, then you can simply add them together normally.