# Fibonacci Sequence in BrainF***

I have been trying to write a BrainF*** program that prints the Fibonacci sequence numbers repeatedly. I was wondering whether this is the most efficient way to do it. I basically repeatedly duplicate two cells into a third cell, and shift one cell forward and repeat.

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

• This code causes a time-out in all environments I've tried so far. What environment are you using that makes this work? – Mast Apr 1 '16 at 18:01
• @Mast That would be due to the portability issue that I pointed out in my answer. – 200_success Apr 1 '16 at 18:20
• @Mast I am using a standard brainf*** interpreter (I run bf <file>). – thepiercingarrow Apr 2 '16 at 0:59
• Note (hint) to the reader: check the date of posting to understand the "historical significance", and why it's not considered a normally acceptable question ;-) – janos Apr 2 '16 at 16:11

## Portability

Your first loop immediately subtracts 4 from a cell whose value is 0. It seems like your program is designed to run using the wraparound dialect of Brainfuck, so it would be a good idea to note that in a comment. On the other hand, writing a Fibonacci sequence generator using the 8-bit dialect isn't that useful, because you would overflow after 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233.

However, I'm puzzled by why you would want to do any subtraction at all. After all, the Fibonacci sequence involves addition, not subtraction.

There's no need to cram everything on one line. Best practice would be to insert line breaks after . commands and use indentation to show off the loop structure. Add some spaces as well, to let your code breathe.

## Suggested solution

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

• I find it amusing you're talking about readability in a language that's specifically designed to be hard to read. I mean, it's right there in the name... – Darrel Hoffman Apr 1 '16 at 20:23
• @DarrelHoffman If that's what you think, then please allow me to further correct your misconceptions of the language! – 200_success Apr 1 '16 at 20:26