Skip to content

Commit

Permalink
added fact.bf
Browse files Browse the repository at this point in the history
  • Loading branch information
josephruocco committed Oct 4, 2018
1 parent 0e7f016 commit 6424261
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions math/factorial/brainfuck/fact.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
read n (leave some free space to stop the final loop)
>>,>++++++++[-<------>]
generate all integers from n to 0 separated by 0
<[[->+>+<<]>[-<+>]>-]
set result to 1 and move to integer '1'
<+<
While current integer is not null
[
multiply result by current integer
[->[->+>+<<]>[-<+>]<<]
store result at its new location (and reset temporary cells)
>>>[-<<<<+>>>>]<<[-]<
go to previous integer in the stack
<<]

0 comments on commit 6424261

Please sign in to comment.