Created
January 4, 2017 19:06
-
-
Save smpallen99/40b3040f28095217c0f43337b5d45e5f to your computer and use it in GitHub Desktop.
BrainF__k interpreter test case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Increment data pointer so that it points to next location in memory. | |
< Decrement data pointer so that it points to previous locaion in memory. | |
+ Increment the byte pointed by data pointer by 1. If it is already at its maximum value, 255, then new value will be 0. | |
- Decrement the byte pointed by data pointer by 1. If it is at its minimum value, 0, then new value will be 255. | |
. Output the character represented by the byte at the data pointer. | |
, Read one byte and store it at the memory location pointed by data pointer. | |
[ If the byte pointed by data pointer is zero, then move instruction pointer to next matching ']', otherwise move instruction pointer to next command. | |
] If the byte pointed by data pointer is non-zero, then move instruction pointer to previous matching '[' command, otherwise to next command. | |
Every character is ignored (comments) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0! = 1 | |
1! = 1 | |
2! = 2 | |
3! = 6 | |
4! = 24 | |
5! = 120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+++++++++++++++++++++++++++++++++ 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 | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment