From 64242610b6129e09fdee48bc45c685599c1b7117 Mon Sep 17 00:00:00 2001 From: josephruocco Date: Thu, 4 Oct 2018 10:11:45 -0400 Subject: [PATCH] added fact.bf --- math/factorial/brainfuck/fact.bf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 math/factorial/brainfuck/fact.bf diff --git a/math/factorial/brainfuck/fact.bf b/math/factorial/brainfuck/fact.bf new file mode 100644 index 0000000000..34de599275 --- /dev/null +++ b/math/factorial/brainfuck/fact.bf @@ -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 +<<]