r/brainfuck • u/lumasDC • Feb 16 '20
Fibonacci Printer
Use with a cell size as high as possible to avoid overflow/rollover.
>+[[>+>+<<-]<[>>+<<-]>>[<+>-]>[<<<+>>>-]<<[->+>+<<]>>[-<<+>>]++++++++++>>>>>+<<<<<<[[->->+<[>-<[->>+<<]]>>[-<<+>>]<[-<++++++++++>>>+<<]<<]>>>>>>[>]+++++++++++[<]<<<<[->>>>>[>]<-[<]<<<<]>>>[-<<<<+>>>>]<<<++++++++++<]>[-]>>>>>->[>]<[>++++++[-<++++++++>]<-.[-]<]++++++++++.[-]<<<<<<<]
1
Upvotes
2
u/danielcristofani Feb 16 '20 edited Feb 16 '20
Big cell sizes won't help you much. Say you use 128-bit cells. This would give an inaccurate result for F(187) (should be 538522340430300790495419781092981030533), except that it would take it many quintillions of years to get that far.
The right answer is to divide the numbers across multiple cells, so you can compute the first 1000 Fibonacci numbers in one second and then keep going at full speed. Fortunately this isn't too hard. I've been writing up detailed comments on a series of my programs; that one is at http://www.hevanet.com/cristofd/brainfuck/fib_explained.b