User:None1/BF

From Esolang
Jump to navigation Jump to search

Some brainfuck programs I wrote (this is a copy of my brainfuck programs at GitHub).

Kolakoski sequence

This outputs the Kolakoski sequence, as the sequence is infinitely long, the program never terminates.

+++++++[>+++++++<-]>.+..-..[-] ; Print out "12211"
+>>>>++>>>>++>>>>+>+>>>+>>+<<<<<<<<<<<<<<<<<<< ; Store 1 2 2 1 1
                                               ;            s^ f^
+[ ; Infinite loop
    >>-[+>>>>-]+ ; Go to the slow pointer
    <[
        >>-[+>>>>-]+ ; Go to the fast pointer
        >>[>>>>]+++ ; Set top value to 3
        <<-[+<<<<-]+ ; Go back to the fast pointer
        <<[>>>+>[>>>>]<<<<-<<-[+<<<<-]+<<-] ; Set top value to 3 minus fast pointer value
        >>>[<<<+>>>-] ; Restore fast pointer value
        <<<[>>>>]<<<++++++[<++++++++>-]<. ; Output top value as character
        >++++++[<-------->-] ; Restore to number
        -[+<<<<-]+<- ; Decrement slow pointer value
    ]
    >>>[<<<+>>>-] ; Restore slow pointer value
    <-[+>>>>-]+ ; Go to the fast pointer
    [>>[>>>>]<<+<<<<-[+<<<<-]] ; Move fast pointer to top
    <-[+<<<<-]+[>>>>+<<<<-] ; Move slow pointer to the next
    >>-[+<<<<-]+ ; Move back to infinite loop flag
]

The minimized version is like this:

+++++++[>+++++++<-]>.+..-..[-]+>>>>++>>>>++>>>>+>+>>>+>>+<<<<<<<<<<<<<<<<<<<+[>>-[+>>>>-]+<[>>-[+>>>>-]+>>[>>>>]+++<<-[+<<<<-]+<<[>>>+>[>>>>]<<<<-<<-[+<<<<-]+<<-]>>>[<<<+>>>-]<<<[>>>>]<<<++++++[<++++++++>-]<.>++++++[<-------->-]-[+<<<<-]+<-]>>>[<<<+>>>-]<-[+>>>>-]+[>>[>>>>]<<+<<<<-[+<<<<-]]<-[+<<<<-]+[>>>>+<<<<-]>>-[+<<<<-]+]