Can someone please post a code piece for multiplying two one-digit numbers in the programming language brainf*ck?
,>,< input numbers at cell #1 #2
[
> go to cell #2
[
->+>+<< move data to cell #3 #4
]
>> go to cell #4
[
-<<+>> move data to cell #2
]
<<< go to cell #1
- decrement cell #1
]
>>. output cell #3
Program read to cell #1, #2 and result will be appear in cell #3
I use BF interpreter where I can input numbers as numbers(not ASCII Symbols)
Well, I might not have the most efficient way around it, but it works. I did things in a specific ways so that it would work with all of these
2*3=6
6*7=42
4*5=20
So, here it is:
read
>, >, <<
convert from ascii
+++++ +
[
>----- ---
>----- ---
<<-
]
multiply
>[
>[>+>+<<-]
>[<+>-]
<<-
]
separate numbers
>[-]>+> >+++++ +++++<
[
- >- [>>>]+++++ +++++<<+
[<<<]>>>>
]
<-
<+++++ +++++>>>[-<<<->>>]<<<
convert to ascii
<+++++ +
[
>+++++ +++>
[+++++ +++>]
<[<]>-
]
print
>>[.<<]<[<<]>>.
I used this interpreter: http://esoteric.sange.fi/brainfuck/impl/interp/i.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With