Now, a while ago, I said in chat:
I'm done with BF programming.
Except I guess I was lying. Here's a Brainfuck program I wrote, that prints out the multiplication tables up to 12. Fairly simple; what it does:
- Loops through 1-12; let's say the current value we are at is
x
- Loop 12 times, adding
x
each time, and prints the result - Resets the number
- Loop 12 times, adding
The code:
Cell 0 is space
Cell 1 is newline
Cell 2 is outer counter
Cell 3 is outer number
Cell 4 is inner counter
Cell 5 is inner number
Cell 6 is copy workspace
>++++[<+++++ +++>-] set cell 0 to space
+++++ +++++ set cell 1 to new line
>+++++ +++++ ++ set counter to 12
[ while counter is not 0
>+ increment number
>+++++ +++++ ++ set inner counter to 12
[ while inner counter is not 0
<[>>+>+<<<-]>>>[<<<+>>>-] increment inner number
>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]
<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>
[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++
[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++
[->++++++++<]>.[-]]<<++++++[-<++++++++>]
<.[-]<<[-<+>] print number gotten off SO
<<<<<<. print space
>>>>- go to inner counter
] end inner loop
>[-]< reset number
<<<. print new line
>- go to counter
] end outer loop
Compressed:
>++++[<++++++++>-]++++++++++>++++++++++++[>+>++++++++++++[<[>>+>+<<<-]>>>[<<<+>>>-]>+++++++
+++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]
>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<
.[-]<<[-<+>]<<<<<<.>>>>-]>[-]<<<<.>-]
Output:
1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 6 9 12 15 18 21 24 27 30 33 36
4 8 12 16 20 24 28 32 36 40 44 48
5 10 15 20 25 30 35 40 45 50 55 60
6 12 18 24 30 36 42 48 54 60 66 72
7 14 21 28 35 42 49 56 63 70 77 84
8 16 24 32 40 48 56 64 72 80 88 96
9 18 27 36 45 54 63 72 81 90 99 108
10 20 30 40 50 60 70 80 90 100 110 120
11 22 33 44 55 66 77 88 99 110 121 132
12 24 36 48 60 72 84 96 108 120 132 144
Some notes:
- The multiplication table is missing formatting. I realise that, and will add it some time later, if I can figure out how to compare two values.
- I realise it doesn't work for multiplication tables of
16
or higher, due to BF cell sizes being only 8 bits, or up to255
. The value16 * 16
would result in256
, setting the value of the cell to be0
. Is this unavoidable? Or is there a trick to it?
Concerns:
- Does it make sense? (Considering it's Brainfuck, it shouldn't make sense...)
- Do my "comments" make sense?
- Are there redundant commands that I can remove/reduce?