Why is this program valid? I was trying to create a syntax error

I really like brainfuck. It's one of my favourite languages (it should go without saying that it's a strictly "fucking around" language though haha). It makes you think completely differently to get anything done, but it's strangely familiar. It tickles the same parts of my brain that programming usually does but in a new and exciting way, and I like that a lot.

As for why I've used so many different interpreters: one for the Windows box at home, one for the Linux laptop, and this one in Javascript when I need better debugging tools. (Fun fact: That bf debugger is the first open source project I ever contributed to. < from cell 0 put you on cell 255, but > from 255 put you on 256 and > from 256 put you on 0 again. I noticed that the "do we need to loop back to 0 yet" check was using > when it should have used >=.)

I don't mean to toot my own horn or anything (not that this is that big of a deal anyway) but when you put your mind towards working with brainfuck you can do some pretty neat things. For example:


Problem

Given a space-separated string that lists a nonempty subset of the numbers 1 through 10 in order, print ASCII art representing the pins at the end of a bowling lane, with a pin drawn as 0 if it was in the input and . if it was not.

Solution

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

That's one I'm particularly proud of, but if it's doable with a computer it's doable in brainfuck. Literally! :D

/r/ProgrammerHumor Thread Parent Link - stackoverflow.com