Skip to main content
added 923 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

Another small improvement

The order of the tape values does matter a little bit. I realized that the order you wanted to go to the cells was 70 100 40 70 100 40, but my BF program kept the cells in the order 40 70 100. So by reordering the cells slightly, I saved 2 run-time instructions and reduced source code length by 2! (Yay!)

My updated code: (383 run-time instructions, source code length 122)

+++++ +++++ [-          10 times
  >+++++ ++             10 * 7 = 70
  >+++++ +++++          10 * 10 = 100
  >++++                 10 * 4 = 40
  <<<] 70 100 40
>++.                      40 72 100 print 'H'
>+.+++++ ++..+++.         40 72 111 print 'ello'
>++++.----- ----- --.     32 72 111 print comma and space
<<+++++ +++++ +++++.      32 87 111 print 'W'
>.+++.----- -.----- ---.  32 87 100 print 'orld'
>+.                       33 87 100 print '!'

Another small improvement

The order of the tape values does matter a little bit. I realized that the order you wanted to go to the cells was 70 100 40 70 100 40, but my BF program kept the cells in the order 40 70 100. So by reordering the cells slightly, I saved 2 run-time instructions and reduced source code length by 2! (Yay!)

My updated code: (383 run-time instructions, source code length 122)

+++++ +++++ [-          10 times
  >+++++ ++             10 * 7 = 70
  >+++++ +++++          10 * 10 = 100
  >++++                 10 * 4 = 40
  <<<] 70 100 40
>++.                      40 72 100 print 'H'
>+.+++++ ++..+++.         40 72 111 print 'ello'
>++++.----- ----- --.     32 72 111 print comma and space
<<+++++ +++++ +++++.      32 87 111 print 'W'
>.+++.----- -.----- ---.  32 87 100 print 'orld'
>+.                       33 87 100 print '!'
added bfdev generator version and comparison
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

I also used a certain Brainfuck Developer IDE that includes a "Text generator" tool to generate BF code for your string, this tool produced the following code:

>++++++++[<+++++++++>-]<.
>++++[<+++++++>-]<+.
+++++++.
.
+++.
>++++++[<----------->-]<-.
------------.
>+++++[<+++++++++++>-]<.
>++++[<++++++>-]<.
+++.
------.
--------.
>++++++[<----------->-]<-.

Here is an overview of the number of instructions being performed at run-time in the different versions:

$$ \newcommand{smallm}[0]{\overset{n\ \gg\ m}{\longrightarrow}} \begin{array}{|l|c|c|} \hline \\ & \textrm{Your code} & \textrm{200_success A} & \textrm{200_success B} & \textrm{My code} \\ \hline \\ \textrm{Next} & 0 & 99 & 69 & 35 \\ \hline \\ \textrm{Previous} & 0 & 90 & 64 & 34\\ \hline \\ \textrm{Print} & 13 & 13 & 13 & 13\\ \hline \\ \textrm{Add} & 193 & 709 & 466 & 256\\ \hline \\ \textrm{Subtract} & 160 & 21 & 22 & 36\\ \hline \\ \textrm{Start While} & 0 & 1 & 1 & 1\\ \hline \\ \textrm{End While} & 0 & 10 & 10 & 10\\ \hline \\ \textrm{Total} & 366 & 943 & 645 & 385\\ \hline \end{array}$$$$ \newcommand{smallm}[0]{\overset{n\ \gg\ m}{\longrightarrow}} \begin{array}{|l|c|c|} \hline \\ & \textrm{Your code} & \textrm{200_success A} & \textrm{200_success B} & \textrm{My code} & \textrm{bfdev tool} \\ \hline \\ \textrm{Next} & 0 & 99 & 69 & 35 & 39 \\ \hline \\ \textrm{Previous} & 0 & 90 & 64 & 34 & 39 \\ \hline \\ \textrm{Print} & 13 & 13 & 13 & 13 & 13 \\ \hline \\ \textrm{Add} & 193 & 709 & 466 & 256 & 226 \\ \hline \\ \textrm{Subtract} & 160 & 21 & 22 & 36 & 193 \\ \hline \\ \textrm{Start While} & 0 & 1 & 1 & 1 & 6 \\ \hline \\ \textrm{End While} & 0 & 10 & 10 & 10 & 33 \\ \hline \\ \textrm{Total} & 366 & 943 & 645 & 385 & 549 \\ \hline \end{array}$$

Your code      : 366
200_success A  : 151
200_success B  : 123
My code        : 124
bfdev generated: 185

Here is an overview of the number of instructions being performed at run-time in the different versions:

$$ \newcommand{smallm}[0]{\overset{n\ \gg\ m}{\longrightarrow}} \begin{array}{|l|c|c|} \hline \\ & \textrm{Your code} & \textrm{200_success A} & \textrm{200_success B} & \textrm{My code} \\ \hline \\ \textrm{Next} & 0 & 99 & 69 & 35 \\ \hline \\ \textrm{Previous} & 0 & 90 & 64 & 34\\ \hline \\ \textrm{Print} & 13 & 13 & 13 & 13\\ \hline \\ \textrm{Add} & 193 & 709 & 466 & 256\\ \hline \\ \textrm{Subtract} & 160 & 21 & 22 & 36\\ \hline \\ \textrm{Start While} & 0 & 1 & 1 & 1\\ \hline \\ \textrm{End While} & 0 & 10 & 10 & 10\\ \hline \\ \textrm{Total} & 366 & 943 & 645 & 385\\ \hline \end{array}$$

Your code    : 366
200_success A: 151
200_success B: 123
My code      : 124

I also used a certain Brainfuck Developer IDE that includes a "Text generator" tool to generate BF code for your string, this tool produced the following code:

>++++++++[<+++++++++>-]<.
>++++[<+++++++>-]<+.
+++++++.
.
+++.
>++++++[<----------->-]<-.
------------.
>+++++[<+++++++++++>-]<.
>++++[<++++++>-]<.
+++.
------.
--------.
>++++++[<----------->-]<-.

Here is an overview of the number of instructions being performed at run-time in the different versions:

$$ \newcommand{smallm}[0]{\overset{n\ \gg\ m}{\longrightarrow}} \begin{array}{|l|c|c|} \hline \\ & \textrm{Your code} & \textrm{200_success A} & \textrm{200_success B} & \textrm{My code} & \textrm{bfdev tool} \\ \hline \\ \textrm{Next} & 0 & 99 & 69 & 35 & 39 \\ \hline \\ \textrm{Previous} & 0 & 90 & 64 & 34 & 39 \\ \hline \\ \textrm{Print} & 13 & 13 & 13 & 13 & 13 \\ \hline \\ \textrm{Add} & 193 & 709 & 466 & 256 & 226 \\ \hline \\ \textrm{Subtract} & 160 & 21 & 22 & 36 & 193 \\ \hline \\ \textrm{Start While} & 0 & 1 & 1 & 1 & 6 \\ \hline \\ \textrm{End While} & 0 & 10 & 10 & 10 & 33 \\ \hline \\ \textrm{Total} & 366 & 943 & 645 & 385 & 549 \\ \hline \end{array}$$

Your code      : 366
200_success A  : 151
200_success B  : 123
My code        : 124
bfdev generated: 185
source code length summary
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312

Here is an overview of the number of runinstructions being performed at run-time instructions in the different versions:

And here is an overview of the source code length of the different versions:

Your code    : 366
200_success A: 151
200_success B: 123
My code      : 124

As you can see, using loops doesn't normally improve performance. The reason for this is that the instead of using only one cell, loops uses more. There is no faster way to go from 0 to 100 than to write + 100 times. Using loops does, however, reduce code length.

Here is an overview of the number of run-time instructions in the different versions:

As you can see, using loops doesn't normally improve performance. The reason for this is that the instead of using only one cell, loops uses more. There is no faster way to go from 0 to 100 than to write + 100 times. Using loops does, however, reduce code length.

Here is an overview of the number of instructions being performed at run-time in the different versions:

And here is an overview of the source code length of the different versions:

Your code    : 366
200_success A: 151
200_success B: 123
My code      : 124

As you can see, using loops doesn't normally improve performance. The reason for this is that instead of using only one cell, loops uses more. There is no faster way to go from 0 to 100 than to write + 100 times. Using loops does however reduce code length.

mathjax!
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312
Loading
added 1572 characters in body
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312
Loading
Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 160
  • 312
Loading