3 ms·
beautiful! 12 minutes : >,[[>,]]<[.<] edit: of course it should be >,[>,]<[.<]
by VladRussian 15y ago
beautiful! 12 minutes :
>,[[>,]]<[.<]
edit: of course it should be
>,[>,]<[.<]
- redthrowaway 15y ago">,[>,]<[.<]" pStr++; *pStr = getc(stdin); //or wherever while *pStr { pStr++; *pStr = getc(stdin); } pStr--; while *pStr { putc (*pStr, stdout) pStr--; } It'll print the reverse of a string, but it will also print everything before it until it hits a null byte. I'd add <[-] to the beginning to null out the preceding byte and hope it wasn't important. As silly as brainfuck seems, I could see something like it being used in nanobots (should such a thing ever come to pass), where memory would be at a severe premium.
- meatmanek 15y agoBrainfuck doesn't really save more memory than any other Turing machine language. However, it could save you silicon space in your hypothetical nanobot because everything is an increment -- incrementing can be done by a chain of half adders, which require fewer gates than full adders.
- VladRussian 15y ago>It'll print the reverse of a string, but it will also print everything before it until it hits a null byte. exactly! The brainfuck execution starts with the pointer at the first byte of zero-filled array: http://www.muppetlabs.com/~breadbox/bf/ http://www.muppetlabs.com/~breadbox/bf/ So the first ">" in my program moves the pointer to the next byte, and this skipped first byte would serve as a stopper when pointer moves back.
- redthrowaway 15y agoAh. I wasn't aware of that part of the spec. In that case, then, the code would work. It's an interesting language, and one that I'm not convinced is so entirely without practical application as is commonly stated.