# Print 'A' 1000 times with BrainFuck

What is the best BrainFuck code (in terms of code size) to print 'A' 1000 times ?

My approach is:

• set 'A' to p[0]
• set 255 to p[1] to display 255 'A', 3 times
• set 235 to p[1] to display 235 'A'

This is not effective but I cannot find a way to use tow counters simultaneously like a multiplication

Is there a better approach than a multiplication ?

A more general question: is there a rule to make a multiplication with a large number with the smallest possible code?

• This is a good place to start. Welcome to Code golf! :) – FryAmTheEggman Jun 16 at 21:02
• I think you want to just use a nested loop, but I don't know BF very well. Have you seen Brainfuck tips? Also probably the esolangs page on Brainfuck constants would be a useful resource here. – Jonathan Allan Jun 16 at 21:02
• I think you should clarify best BrainFuck code. Are you in search of most readable, most elegant, using the least amount of + characters or simply highest brevity? – Jonathan Frech Jun 16 at 22:17
• @Jonathan Allan: Yes, that's the purpose of this question : How to use a nested loop. It's a fascinating language close ASM but I don't understand some aspects – Nelson G. Jun 17 at 6:31
• Could I use this variant on BF -> github.com/gergoerdi/brainfuck64 – Shaun Bebbers Jun 17 at 10:50

The method you seem to currently be using is 39 bytes:

>>+++[<-[-<.>]>-]++++[<----->-]<-[-<.>] (not including getting the A) (Try It Online!)

(loop 3 times, each time set the counter to 255 and print that many times, then subtract 20, subtract 1, and print that many times)

However, it is much shorter to loop 250 times and print 4 times each time (thanks to jimmy23013 for optimizing this over my original loop-4 loop-250 print-1 solution):

>------[<....>-] (16 bytes)

If your cells are unbounded (I'm assuming they're 8-bit otherwise you probably wouldn't try using 255 for golfing):

>>++++++++++[<++++++++++[<..........>-]>-] (42 bytes).

• this seems to assume 8-bit cells, though... – John Dvorak Jun 16 at 21:22
• @JohnDvorak: The question mentioned setting cells to 255 as a part of the most effective solution the OP could think of. That seems like a pretty clear indication of (ab)using 8-bit cell wrapping. – randomdude999 Jun 16 at 21:25
• @JohnDvorak What randomdude999 said, but I did add a method using 10x10x10 in case the cells are unbounded. – HyperNeutrino Jun 16 at 21:37
• 250 times .... would be shorter. – jimmy23013 Jun 17 at 9:36
• @jimmy23013 ... not sure how I didn't think of that an still optimized my 10x10x10 solution to do that LOL. thanks! – HyperNeutrino Jun 17 at 13:35

the shortest way to get the number 65 for 'A' is >+[+[<]>>+<+]>, and then you just add HyperNeutrino's >------[<....>-] to the end of that. so the full code becomes >+[+[<]>>+<+]>>------[<....>-] (30 bytes)

• How do you know that way is shortest? It certainly is shorter but do you know for certain that noone will find a shorter one? – Wheat Wizard Aug 11 at 12:21
• – jimmy23013 Aug 11 at 14:16
• @SriotchilismO'Zaic yeah I didn't really mean it was the shortest lol – Sagittarius Aug 30 at 20:56

# 47 Bytes ( No Underflows )

I just did this solution in 47 bytes. I tried doing it in a different manner than I normally would trying to save space by juggling counters between two values. It assumes that A is preloaded into p[4].

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


## Explained

Place 5 into p[0]
+++++
Loop 5 times to put p[1]=20, p[2]=25
[>++++>+++++<<-]>
Loop 20 times
[>
Move pointer to p[2] and loop 25 times.
Also move p[2] to p[3]

[
Increment p[3] from 0, effectively moving the value from p[2] to p[3]
>+
Print p[4]
>.
Decrement p[2]
<<-]
Shift over to p[3]
>
[
Decrement p[3]
->
Print p[4]
.<
Increment p[2]
<+>]
Move back to p[1] and decrement
<<-
Repeat until p[1] is 0
]