Skip to content

Instantly share code, notes, and snippets.

@scturtle
Created April 30, 2014 07:28
Show Gist options
  • Save scturtle/ffb82423976c7f2c4341 to your computer and use it in GitHub Desktop.
Save scturtle/ffb82423976c7f2c4341 to your computer and use it in GitHub Desktop.
print 0 to 99 in brainfuck
ref: http://www'iwriteiam'nl/Ha_bf_intro'html
>++++++++++[<++++++++++>-] (#0=100)
>+++++++[<+++++++>-]+++++++++++<--< (#1=47 #2=11)
[ (loop #0)
>+ (inc #1)
>- (dec #2)
(test if #2 is 0 using #3 #4)
[>+>+<<-] >[<+>-] (move #2 to #3 #4; move #3 to #2)
+ <[ >- < (inc #3; if #2; dec #3; back to #2)
[-]] (endif #2) >>[<<+>>-] (copy #4 back to #2) <[ (if #3)
>+ (#4=1)
> (if #5 is 0 using #7 #8)
[>>+>+<<<-] >>[<<+>>-] (move #5 to #7 #8; move #7 to #5)
+ <<[ >>- (inc #7; if #5; dec #7)
>+ (inc #8 and will be copied to #5)
<<- (dec #6)
(todo test #6=0)
<[-]] (back to #5; endif #5) >>>[<<<+>>>-] (#8 to #5) <[ (if #7)
<< >+++++++[<+++++++>-]+++++++++ (#5=49 #6=9)
>-](back to #7; endif #7)
<<<<-] (back to #3; endif #3)
>[ (if #4==1)
<<++++++++++ (#2=10)
< ---------- (#1 dec 10)
>>>-]
(print out)
> [<+<+>>-] <<[>>+<<-] (to #5; move #5 to #3 #4; move #3 to #5)
>>[.[-]] (if #5; print; clear #5;)
<[>+<-] (#4 to #5)
<<<. (print #1)
>>++++++++++.[-] (use #3 print \n)
<<<-] (back to #0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment