Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81333 / brainfsck / examples / fact.bf
diff options
context:
space:
mode:
Commitadd56ccba064ed1012a00319834efeee222516a7 (patch)
Author
 Georgi Bojinov <georgi.bojinov@hotmail.com>
2018-11-19 08:57:03 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-19 08:57:03 +0200
Files2cd6d694b04451d1d0bd9d222e366844f8c4daa9 /homework/81333/brainfsck/examples/fact.bf
IPL-add56ccba064ed1012a00319834efeee222516a7.tar
IPL-add56ccba064ed1012a00319834efeee222516a7.tar.gz
IPL-add56ccba064ed1012a00319834efeee222516a7.zip
Parent12232668d931b0f3593807d2096a2c2f26844b0b (diff)
Add homework 3 - brainfsck interpreter (#55)
* Add brainfsck interpreter * Remove unused imports in Main * Add .gitignore * Fix example commands
1 files changed, 42 insertions, 0 deletions
-rw-r--r--homework/81333/brainfsck/examples/fact.bf42
diff --git a/homework/81333/brainfsck/examples/fact.bf b/homework/81333/brainfsck/examples/fact.bf
new file mode 100644
index 0000000..197f331
--- /dev/null
+++ b/homework/81333/brainfsck/examples/fact.bf
@@ -0,0 +1,42 @@
++++++++++++++++++++++++++++++++++ c1v33 : ASCII code of !
+>++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++ c2v61 : ASCII code of =
+>++++++++++ c3v10 : ASCII code of EOL
+>+++++++ c4v7 : quantity of numbers to be calculated
+> c5v0 : current number (one digit)
+>+ c6v1 : current value of factorial (up to three digits)
+<< c4 : loop counter
+[ block : loop to print one line and calculate next
+>++++++++++++++++++++++++++++++++++++++++++++++++. c5 : print current number
+------------------------------------------------ c5 : back from ASCII to number
+<<<<.-.>.<.+ c1 : print !_=_
+
+>>>>> block : print c6 (preserve it)
+> c7v0 : service zero
+>++++++++++ c8v10 : divizor
+<< c6 : back to dividend
+[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<] c6v0 : divmod algo borrowed from esolangs; results in 0 n d_n%d n%d n/d
+>[<+>-] c6 : move dividend back to c6 and clear c7
+>[-] c8v0 : clear c8
+
+>> block : c10 can have two digits; divide it by ten again
+>++++++++++ c11v10: divizor
+< c10 : back to dividend
+[->-[>+>>]>[+[-<+>]>+>>]<<<<<] c10v0 : another divmod algo borrowed from esolangs; results in 0 d_n%d n%d n/d
+>[-] c11v0 : clear c11
+>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]c13v0 : print nonzero n/d (first digit) and clear c13
+<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]] c12v0 : print nonzero n%d (second digit) and clear c12
+<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-] c9v0 : print any n%d (last digit) and clear c9
+
+<<<<<<. c3 : EOL
+>>+ c5 : increment current number
+ block : multiply c6 by c5 (don't preserve c6)
+>[>>+<<-] c6v0 : move c6 to c8
+>> c8v0 : repeat c8 times
+[
+<<<[>+>+<<-] c5v0 : move c5 to c6 and c7
+>>[<<+>>-] c7v0 : move c7 back to c5
+>-
+]
+<<<<- c4 : decrement loop counter
+]