c++ golf

I got this idea from the Perl guru forums. In c++ golf one person gives a problem and everyone else try's to solve it with the least lines. Of course in Perl insane one liners are possible but it should still be fun to do in c++. Any one is free to give a problem so bring em on people!
There is nothing wrong with c++ insane one liners.
Is a one liner 80 chars or less, or just no line feeds?
Here you go. A brainfuck interpreter.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

int main(){
    int mp = 0, memory[1024] = {0}, ip, layer;
    std::string code;

    while( ip = -1, std::getline( std::cin, code ) && code != "quit" ){
        while(++ip < code.size() && (memory[ mp += code[ip] == '>' ? +1 : code[ip] == '<' ? -1 : 0 ] 
             += code[ip] == '+' ? +1 : code[ip] == '-' ? -1 : 0, 1))
            if( layer = code[ip] == '[' ? +1 : code[ip] == ']' ? -1 : 0,
                code[ip] == '[' && memory[mp] == 0 || code[ip] == ']' && memory[mp] != 0 )
                while(ip += memory[mp] == 0 ? +1 : -1,
                      !( (layer += code[ip] == '[' ? +1 : code[ip] == ']' ? -1 : 0) == 0 && 
                      ( code[ip] == ']' && memory[mp] == 0 || code[ip] == '[' && memory[mp] != 0 ) ) &&
                      ip < code.size());
        std::cout << mp << " : " << memory[mp] << std::endl;
    }
    return 0;
}

I assumed a number of lines = number of ; . There are 5 of them.
I think there is a couple of things I could change to cut down to 3. Maybe I'll do that later..

Though I think it would be best to count number of symbols.
I assumed a number of lines = number of ;

You could just use the comma operator then.

Though I think it would be best to count number of symbols.

And that would encourage people to use dumb variable names like 'a', 'b', etc.

I think counting LOC is kind of dumb and hard to quantify anyway...
if a line feed means ending a line with a ; then ya a one liner is just that. one line of code. google crazy Perl one liners. oh forgot to say: comments don't count towards line count.
You can count lines as the number of expressions
You could just use the comma operator then.
not for ifs, whiles, returns and declarations.

And that would encourage people to use dumb variable names like 'a', 'b', etc.
, which is a lot better than abusing the comma.

I think counting LOC is kind of dumb and hard to quantify anyway...
we aren't trying to write good code here, you know.

You can count lines as the number of expressions
sounds ok..
Topic archived. No new replies allowed.