quack quixote quack quixote - 4 months ago 14
Brainfuck Question

Port dos2unix to brainfuck

I got into an argument over on SuperUser.com about useless answers and found myself challenging the other poster to answer the question in brainfuck. He didn't take me up on it, but now I'm curious.

All the program needs to do is convert CRLF line endings to LF (dos-style to unix). Any bf coders around that can help out?

Answer

Here you go:

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

Assumes that EOF is indicated by an input value of 0 (this is the default on beef, which I used to test, and is a reasonable choice; I think it might also support EOF leaving the character unchanged, but I didn't test that). Also assumes that the file ends with a LF (actually, it replaces the last character with LF). Handles CR correctly if not part of a CRLF pair (that is, it outputs lone CRs).

Took maybe an hour to write and test, and that includes learning Brainfuck from the beginning.

Comments