I want to read in a number with any number of digits with bf. I know how to read in the correct number of digits if I set it manually, like this:
,>,>, 2 Read in 3 digits
<< 0
--------
--------
--------
--------
--------
-------- 45 decrements
> 1
--------
--------
--------
--------
--------
--------
> 2
--------
--------
--------
--------
--------
--------
[>+<-]< 1 Copy digit 3 to cell 3
[>>++++++++++<<-]< Copy 10 * digit 2 to cell 3
Copy 100 * digit 1 to cell 3
[>>>>++++++++++ 4
[<++++++++++>-] 4
<<<<-]>>> 3
>++++++++++..< Add 2 line breaks
., Print and Pause
But I'd rather be able to set a number in cell 0
and then automatically multiply the right number of times for each digit. What would I be best off doing?
This link should be quite helpful: http://esolangs.org/wiki/brainfuck_algorithms
It contains algorithms for multiplication and also an IF condition as well as boolean comparisons (to check if, for example, the user pressed enter [character 10] to end the input.)
Then what you do is this (I will write some pseudocode and then it's up to you to implement it using the algorithms described there). I will tell you also give pseudocode on how to implement a while loop at the end since that is not included in that page (but pretty simple nonetheless... relatively). You will definitely be amazed when you manage to understand exactly what each character is doing :D. Anyway, here goes:
you need two cells A and B
And here's a bit of info about how to create a while loop. Suppose you have this code:
while (condition) {body}
. I will assume you managed to implement the code for the condition using the link I gave you earlier. You need a cell in which to store the result of the condition, which I'll callC