Created
April 23, 2020 20:56
-
-
Save Sinthorion/f1410f87e03ff51ba2d5144a9edfb14f to your computer and use it in GitHub Desktop.
This file contains 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
[ | |
Encodes the input string, until newline, to a Brainfuck program that prints this string | |
The BF code will use the current cell only, which is the fastest possible way to print | |
in Brainfuck, despite producing longer code than other methods. | |
registers: | |
- '+'/'-'/'.' | |
- prev | |
- input | |
- prevdup1 | |
- newdup1 | |
- cmp | |
- prevdup2 | |
- newdup2 | |
] | |
++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ +++ | |
>>, | |
[<+<.>>-] | |
<<+++.---> | |
# | |
---- ---- --[++++ ++++ ++ | |
[>>+>>>+<<<<<-] | |
>,[<+>>>+>>>+<<<<<-] | |
# | |
>>> go to cmp | |
>[>[-<->>>-<]>+[-<<<+>[-]>>>]<<<]>[-]<< cmp (consumes prev2 and new2) | |
[- if prev gt new | |
>-< set else | |
<[<->-] prev sub new | |
<<<<++>>>> switch to minus | |
<[<<<.>>>-] | |
<<<+.--->>> print dot and reset to plus | |
>> | |
]>+[- else (prev le new) | |
<<<[>-<-] new sub prev | |
>[<<<<.>>>>-] | |
<<<<+++.--->>>> print dot | |
>> | |
] | |
<<[-] clear new | |
<[-] clear prev | |
<< | |
---- ---- --] |
This file contains 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
+++++++++++++++++++++++++++++++++++++++++++>>,[<+<.>>-]<<+++.--->----------[++++++++++[>>+>>>+<<<<<-]>,[<+>>>+>>>+<<<<<-]>>>>[>[-<->>>-<]>+[-<<<+>[-]>>>]<<<]>[-]<<[->-<<[<->-]<<<<++>>>><[<<<.>>>-]<<<+.--->>>>>]>+[-<<<[>-<-]>[<<<<.>>>>-]<<<<+++.--->>>>>>]<<[-]<[-]<<----------] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment