# The cell at the end of the rainbow

We all know of, or at least have heard of, brainfuck, one of the most famous and influential esoteric languages. While these days most implementations use an infinite tape, the original compiler by Urban Müller had a tape of 30000 cells. A little known fact* is that there is actually a special value at the end of the tape, something that is almost never interacted with in a typical brainfuck program.

While you could print this value with 29999 >s and a ., brainfuck is known for its short and concise solutions, so your aim is to print this value with the minimum number of characters.

*fiction

### Rules:

• A refresher on the brainfuck instructions:
• +/-: Increment/decrement the current cell, wrapping from 255 to 0 when 255 is incremented and vice-versa
• </>: Move the pointer left/right on the tape
• .: Print the value of the current cell.
• [: Jump to the corresponding ] if the value at the cell is 0
• ]: Jump to the corresponding [ if the value at the cell is not 0
• In this case , (Get input) does nothing, as the original compiler leaves the cell unchanged on EOF, and this program should receive no input.
• The tape is initially filled with all 0s, except for cell 30000, which contains an unknown value
• The pointer starts at cell 1 and should end on cell 30000, having printed it.
• Cells to the left of 1 and to the right of 30000 have undefined behaviour, so solutions should not visit these cells.
• Note that the value at 30000 is may be a 0, so simply looping until you hit a non-zero cell will not work.
• You should print only the value at cell 30000
• The shortest solution wins!
• Tie-breaker is the more efficient program (executes in the least steps), followed by the fastest submission time.

Tip: Esolanging Fruit suggests using https://copy.sh/brainfuck to test your code. The specs are as described in this challenge, and you can select the abort option so your program halts if it goes out of bounds.

• Sandbox (deleted) – Jo King Mar 1 '18 at 4:32
• 1 byte: .. I win. – Esolanging Fruit Mar 1 '18 at 5:23
• @EsolangingFruit Let me have my delusions please... – Jo King Mar 1 '18 at 5:38
• I suggest changing the rule to "initially all the cells have the value of 0, except the last cell which have an unknown value". – user202729 Mar 1 '18 at 6:07
• Tip for anyone doing this: copy.sh/brainfuck is probably the best site for doing this, as it implements BF as described in this challenge and has a 30k tape by default. Moving right past the end of the tape causes the interpreter to hang. – Esolanging Fruit Mar 1 '18 at 6:33

# 54 Bytes

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


119 x 252 = 29988. Straightforward nested loop.

I used this tool to verify that the pointer stops at 29999.

# 50 bytes

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


Try It Here!

The first section (>+[>+[<]>->+]>-<<) sets up the tape as

0*12 121' 0 110


The next section ([>>-------[[>]+[<]>-]<<-]) iterates 121 times, appending 249 1s to the end of the tape each time. If you're quick with math, you might realise this 121*249 results in 30129 1s, but the first iteration has the leftover 110 to deal with and only appends (110-7) 103 1s to the tape, meaning there's only 29983 1s. The final tape looks like:

0*12 0' 0 0 1*29983 0 ???


And a final >>>[>]>. to print the value.

Some other algorithms of note:

• 252*119 = 29988 (also 50 bytes)
• 163*184 = 29992 (56 bytes)
• 204*147 = 29988 (60 bytes)
• 153*196 = 29988 (56 bytes)
• 191*157 = 29987 (57 bytes)
• 254*118 = 29972 (56 bytes)
• This one is the one I consider the next closest to beating 50, since the extra bytes are basically just travelling the extra distance. If I could find an algorithm that generates 118 and travels further than 14 cells, this could beat it.

# 81

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


This moves over by 150 cells 200 times.

This is much longer than I'd like it to be, and there's a serious obstacle to golfing:

I no longer know why I works.

This is littered with compensations for off-by-ones to the point where some of them could probably cancel out. I've added and deleted various segments so much that I no longer remember why I put certain things where they are (for example, why does the first part initialize the tape cells to 199 and 151 instead of 200 and 150?).

Here is my commented version of this monstrosity anyways, in the hope that I (or someone else) might find them useful:

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

0 0 0 199' 155

[
n' k 0
>[
n k' j
->+[[->+<]<]>
0' n k－1 j＋1 OR
n 0 0' j＋1
>>
]
0*k n 0 0 k 0'
<[-<<+>>]<<<-
0*k n－1' k
]
>-------[[->+<]>-]>.

• This doesn't actually print the value, and if the value is positive it overflows. But a great attempt – Jo King Mar 1 '18 at 6:34
• Then add a ., would it help? – user202729 Mar 1 '18 at 11:56
• @JoKing Fixed that. – Esolanging Fruit Mar 1 '18 at 16:38