Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Welcome to this new playground about the BF language. Make sure you already read
- Getting started with BrainFuck
- BrainFuck part 2 - Working with arrays
- BrainFuck part 3 - Write a BF interpreter in BF
- BrainFuck part 4 - Advanced maths
- BrainFuck part 5 - Math sequences
- BrainFuck part 6 - 16-bit integers
- BrainFuck part 7 - Quine (+ some non-BF quine theory)
- BrainFuck part 8 - JS/C#/BF Multi quine
- BrainFuck part 9 - Sort arrays with Bubble and QuickSort
- BrainFuck part 10 - RPN calc tool
playgrounds if you didn't already !
The goal of this playground is to compare different ways to implement recursion based on a very common example: factorial
It may be hard to understand how we can define a recursion in a language that does not even allow functions. But functions are just one way to implement recurion.
Actually the main difference between recursion and iteration is : in order to solve a given problem
- the iterative way solves the problem, starting from a simple version and getting closer to the solution by incrementing the initial result
- the recursive way solves the problem, defining the solution as a function of solutions to the same problem for smaller instances
It can be proven that both ways are equivalent, and that an algorithm that uses one of these can be re-implemented using the other one.
The factorial function
! is recursively defined by
- factorial(0) = 0! = 1
- factorial(n) = n! = n x factorial(n-1)
Let's see different ways to implement this function using BF