Large Numbers in BF

6

2

Background

The language BrainF*** (or simply BF), is an extremely minimal programming language. We're going to strip it back even further by eliminating IO operations; only the sub-langage defined by the operations +-<>[], henceforth referred to as BF-subset, shall be used. The BF variant considered has a tape extending infinitely to the left and right, and cells which can take on any integer value without overflowing, and which are initialized to 0.

For those unfamiliar with BF, this explanation is adapted from the esolangs BF page.

A BF-subset program is a sequence of commands. The commands are executed sequentially, with some exceptions: an instruction pointer begins at the first command, and each command it points to is executed, after which it normally moves forward to the next command. The program terminates when the instruction pointer moves past the last command.

>   increment the data pointer (to point to the next cell to the right).
<   decrement the data pointer (to point to the next cell to the left).
+   increment (increase by one) the byte at the data pointer.
-   decrement (decrease by one) the byte at the data pointer.
[   if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
]   if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.

The Task

If a BF-subset program terminates, its score is defined as the final value of the cell which the program halts at, otherwise 0. Your challenge is to write a program to generate BF-subset programs of each length between 1 and 20 inclusive, such that the total score is maximized.

The winner of the contest will be the entrant with the highest total score; in case of a tie, the shortest program takes the title. Your program must be fast enough for you to run it to completion.

Example Output and Scores

+                   01
++                  02
+++                 03
++++                04
+++++               05
++++++              06
+++++++             07
++++++++            08
+++++++++           09
++++++++++          10
+++++++++++         11
++++++++++++        12
+++++++++++++       13
++++++++++++++      14
+++++++++++++++     15
++++++++++++++++    16
+++++++++++++++++   17
++++++++++++++++++  18
+++++++++++++++++++ 19
+++++++++++++++++++ 20

Here, the total score is 210.

Edit: Changed the maximum length from 17 to 20.

user1502040

Posted 2017-04-04T21:10:42.557

Reputation: 2 196

3How can we test our submissions? Also, given that I expect these values to grow astronomically, I suspect that only the length-17 entry to matter in principle. – xnor – 2017-04-04T21:21:23.923

Isn't this basically meta-golf of something like output Graham's number?

– mbomb007 – 2017-04-04T21:24:02.110

@xnor For short lengths, the values actually stay quite small. – user1502040 – 2017-04-04T21:44:33.290

1

@user1502040 That's fair, I see the really astronomical programs seem to take about twice that many characters. I do have a concern that if someone finds an exceptionally good solution, the only limit will be running it to completion even when the result is mathematically known. So I'd suggest ditching that rule.

– xnor – 2017-04-04T21:48:04.330

Isn't the score actually 105? – ASCII-only – 2017-04-04T21:48:21.100

2Also your program for 20 is too short. – ASCII-only – 2017-04-04T21:59:36.757

Err, Is - a vald program? Technically, the output would be 255. – Matthew Roh – 2017-05-05T08:15:27.823

Although I like this challenge, I think with a limit of 20 all possible solutions have already been crunched to death. The shortest I could find that doesn't appear on the constants page is 22 bytes for 160: ->>>>+[>+[-<+++>]<<+]> (well, it does now, I've just added it).

– primo – 2017-05-06T08:57:16.207

Answers

2

309

+                    01
++                   02
+++                  03
++++                 04
+++++                05
++++++               06
+++++++              07
++++++++             08
+++++++++            09
++++++++++           10
+++++++++++          11
++++++++++++         12
+++++++++++++        13
++++[->++++<]>       16
+++++[->++++<]>      20
+++++[->+++++<]>     25
++++++[->+++++<]>    30
++++++[->++++++<]>   36
+++++++[->++++++<]>  42
+++++++[->+++++++<]> 49

ASCII-only

Posted 2017-04-04T21:10:42.557

Reputation: 4 687

1

Do these all match the best-known values from the constants page?

– xnor – 2017-04-04T21:54:09.273

@xnor Not sure, right now I'm checking through it. EDIT: Yeah, looks like they do, but I might have made a mistake. – ASCII-only – 2017-04-04T21:54:54.503

@orlp But loops only run while the cell has a nonzero value – ASCII-only – 2017-04-04T22:26:26.057

@ASCII-only I misread the answer, I removed my downvote. – orlp – 2017-04-04T22:28:11.250