Brainfuck code snippets. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- calculate base 256 checksum of a bunch of text   use a BF interpreter that allows entering input into a buffer (i.e. not interactive) +,[[[>+<-]],] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- distribute N into memory: n, n-1, n-2, n-3, ... , n - n ++++++++ preload m0 with n [[>+>+<<-]>[<+>-]>[<+>-]<-] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ breadcrumbs fill contiguous memory with a trail N of breadcrumbs '1s' N+ [>>[>]+[<]<-] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ load memory with variable length text string (for display module) ,[>>[>] +[<]<-  [>>[>]<+[<]<-] ,] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Not N (not my discovery or code)   !N = 255 - N ,'A' load N into m0 in this case 65 >-<[>-<-] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - move data pointer n cells to the right ++++++ load m0 with n [>[-]<[>+<-]>-] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - delay/countdown timer, because sometimes brainfuck is just too fast +[>-[-]<-] +[>- [>-[-]<-] <-] +[>- [>- [>- [>- [>- [>- [>- [>- [>-[-]<-] <-] <-] <-] <-] <-] <-] <-] <-] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - A + B with carry, 2 digit base 256 addition A[B + [temp0[B + temp0 -] temp1[- zero - temp1] + zero [temp1 - zero[-]] temp1[- carry + temp1] A -] for: memory0 = A m1 = carry m2 = B m3 = temp0 m4 = temp1 m5 = zero: value is always 0 ++++>>--<<        start with m0=4 m2 = 254 [>>+            start add loop [>+>+<<-]        move m3 back to m2 >[->-<]+>[<->[-]]    set m4 = (m4 == m5) <[-<<<+>>>]        add m4 which is either a 1 or 0 to m1 <<<<-]            end main add loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ n/2 >>n [-<+>[-<->>+>]<<] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ check if N = 0 memory: m0 = flag m1 = N m2 = 0: landing zone m3 m4: breadcrumbs >++++++        load N >>+>+<<<       create breadcrumbs [<+>-          assume that N will be 0 and set flag [<-]           but N isn't 0 so reset flag >              go to N ]              continue working on N >>[>]<[-<]<<   place data pointer at the flag ~ clean up breadcrumbs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - A - B using A + Two's Compliment(B) preload A preload B preload B2C with 255 B[B2C - B -]        compute Not B and put in B2C B2C +            increment Not B to make it Two's Compliment B2C [A + B2C -]        add A to Two's Compliment of B ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Truth Machine +++++++[>+++++++> +++++++<<-]>-<,>[ <->-]<[>>[.]]>>-. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is just a bat. ,             , |\   |\~/|   /| | \__)o o(__/ | \  \ / ^ \ /  /  \=_=\   /=_=/   \ /\\~//\ / dmc    '  " "  ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ find non-zero >>>-<<<          put a non zero value out in memory P +[-[   <-<]>+]>  someone else ||||::::||||||:    similarities +[-[[-]>-<]>+]<  mine                  does not maintain original value                  stops at P for value 1~254                  stops at P-1 for value = 255 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ load fibonacci series in memory >+[[>+>+<<-]>>[<< +>>-]<<<[>>+>+<<< -]>>>[<<<+>>>-]<] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >+[<[>>+>+<<<-]>> >[<<<+>>>-]<<[>+> +<<-]>>[<<+>>-]<] >+            load the first two cells with 0 and 1 [            start perpetual loop     <        go to A     [>>+>+<<<-]    dup A into A+B and Temp0     >>>        go to Temp0     [<<<+>>>-]    move Temp0 back to A     <<        go to B     [>+>+<<-]    dup B into A+B and Temp0     >>        go to Temp0     [<<+>>-]    move Temp0 back to B <            go to new B shifting all operations one to the right ]            close loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[[>>+>+<<< -]>>[<<+>>- ]<[<+>-]>>[ <<+>>-]<<<#] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fibonacci sequence >-[[<+>>>-<-<+]>] http://inversed.ru/InvMem.htm#InvMem_7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ count up >>>++++ [<<<        start with n in m3 [>+>+<<-] >>[<<+>>-] <+ >>- [>+<-]> ] <<<[<]        go back to m0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>++++++ [<<<[>+ >+<<-]> >[<<+>> -]<+>>- [>+<-]> ]<<<[<] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ is N even or odd >+++++++++++++++    load m1 with N >>+>+<<<        create trail of breadcrumbs to locate position of P [-[->]<]+        set m0 = 1 if odd             set m1 = 1 if even >>>[>]            resolve position <[<]             of data pointer P >->-<<            clean up breadcrumbs <            set P to m1 if N is even               or conversly 1 = even: 0 = odd <<            use this one to set P to m0 if N is odd ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ N odd or even: bare minimum     >,             load m1 with N          [-[->]<]+      set m0 = 1 if odd                    set m1 = 1 if even ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ N odd or even? clean version that resolves P     >,              ~load m1 with N (not counted for golf scoring)     >>+>+<<<        ~set 'trail of breadcrumbs' so we can figure out                        where P is     [-[->]<]+       ~if N is odd set m0 = 1     >>>[>]          ~figure out where P is     <[-<]<[-]<      ~go back to m1 and zero out if N is even Pointer P ends on m0   odd: m0 = 1  even: m0 = 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [m2 = (m0 > m1)] m0 = d1 m1 = d2 m2 = G m3 = landing zone (always zero) m4 = copy of d2 used for calculation m5 = start of breadcrumbs equal to d1 +++++>+++<             load d1 and d2 [>>>+>+<<<<-]         dup d1 to mem >>>[<<<+>>>-]         restore d1 >[>[>]+[<]>-]         place breadcrumbs <<<[>>+>+<<<-]        dup d2 to mem >>[<<+>>-]>           restore d2 [>[-]<[>+<-]+>-]     compare d2 with breadcrumbs >[<<[<]<+>>[>]]      set G (m2) to 1 if there are more breadcrumbs to the right >[-]<<[-]<[[-]<]<    clean up breadcrumbs and stop on G ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~