Brainfuck

I’ve started to write brainfuck. It’s just fun. I’ll get a little text to brainfuck converter running soon, I think I’ve got a simple algorithm to do just that. I have to work out the details though.

It will be in C, JavaScript and PHP. Three versions. Just bacause I can. The JavaScript version will be implemented as an app within httpWM.

Update:

I decided not to write a C version (yet) because I just started to write C a month or two ago at school and I keep getting stuck. The JavaScript version will be written when I feel like I have too much spare time. The PHP version is finished and it even beat the crap out of my own hand-calculated brainfucks. The algorithm used is a very simple one. First, determine the smallest ASCII value out of the characters. This value will be used as decrementer for the initial loop that will set usefull values into the memory. These values are calculated by dividing the ASCII value with the decrementer. After that it searches the memory for a value that produces the least output in brainfuck when calculated and printed. It calculates the position and offset, moves the pointer, adjusts the value and prints the character. This will be repeated with a lowered decrementer intil it reaches 1. The shortest brainfuck result is printed. It can be optimized a lot more I think. This is just a simple approach. I’ve put in a binary-safe switch if you want to keep your brainfuck output binary identical to your text input. This will result in quite some more brainfuck code bacause it has to use the char(0), too.

You can download the PHPCLI script here, licensed using the GNU GPL. The interpreter I used can be downloaded here.

3 Responses to “Brainfuck”

  1. Hey Jorrizza,

    That script you writed is very 1337 :P. Im really impressed :).
    I like it very much that you update your blog more often. You know a lot about the stuff you write on the blog.
    I think that it would be a good idea to place the links to the sites you used to gather all the information.
    Keep blogging :)

    Greets,

    Bjorn.

  2. All the info I used can be found on the wikipedia page I’ve linked to. I’m afraid there’s not more to it than that.
    You just have to understand pointers to understand brainfuck. Well, if you can understand arrays it should be enough, too.

  3. I understand that all the info about Brainfuck is published on the wikipedia page.
    But that was not my point, I think it would be a good idea to link several pages for every subject.
    For example:
    You’re busy with AJAX and Javascript, which pages did you use to gain all the knowledge that you have know?
    That would be far more interesting and more helpful than just showing what the possibilities are with that subject, or showing your programming skills ( which we know that you already have :P ).

    Greets,

    Bjorn.

Discussion Area - Leave a Comment