Computer Science Canada

Obfuscated Code Contest

Author:  saltpro15 [ Fri Aug 28, 2009 2:37 pm ]
Post subject:  Obfuscated Code Contest

Hey all,

So this is my implementation of AJ's idea of a "shortest code" contest. I think the majority of people on this forum are comfortable with C++, so I'm using that as the language for this contest(s?).

First Problem:

Let's start easy with this problem from SPOJ..

And shall we say whoever wins this round gets to pick/create the problem next time?

Rules :
- source code must compile
- "size" of code is determined in bytes

Author:  DtY [ Fri Aug 28, 2009 2:43 pm ]
Post subject:  RE:Obfuscated Code Contest

Can we use C since you can compile C as C++?

Author:  saltpro15 [ Fri Aug 28, 2009 2:51 pm ]
Post subject:  RE:Obfuscated Code Contest

sure

Author:  bbi5291 [ Fri Aug 28, 2009 2:52 pm ]
Post subject:  Re: Obfuscated Code Contest

I propose the following rules:
* The code must consist only of ASCII characters.
* The code must compile on g++ with the -ansi flag.
* The length of the source file should be the output of tr -d [:space:] | wc -c.

Author:  saltpro15 [ Fri Aug 28, 2009 2:56 pm ]
Post subject:  RE:Obfuscated Code Contest

good ideas Brian. Unfortunately I can't edit my post on this forum...

Author:  DtY [ Fri Aug 28, 2009 3:10 pm ]
Post subject:  RE:Obfuscated Code Contest

Okay, I got 164 bytes following bbi5291's rules. Gonna see if I can shave off a little more Smile

Author:  bbi5291 [ Fri Aug 28, 2009 3:12 pm ]
Post subject:  Re: Obfuscated Code Contest

Oh right, some that I forgot:
* The code must be platform-independent.
* The usual rule of online judges applies - executing other programs is not allowed.
* The code must always give the correct answer - a program that crashes 90% of the time and works the other 10% of the time is not acceptable. (Hanson actually wrote such code once.)
* The code must exit normally. It must not, for example, segfault, even after it has printed out the correct answer.
However, one should keep in mind that no points are awarded for style. For example, using main() without a return type is not only acceptable, it is recommended. Also, there should be no limit on compile time, runtime or memory usage.

Author:  saltpro15 [ Fri Aug 28, 2009 3:13 pm ]
Post subject:  RE:Obfuscated Code Contest

my best so far is 43 bytes with Ruby... I'll try it in C++

Author:  bbi5291 [ Fri Aug 28, 2009 3:15 pm ]
Post subject:  Re: Obfuscated Code Contest

I thought we were supposed to post our code here? Not only is it the only way to make sure you're following the rules, but it would have some twisted form of educational value... GNU or Microsoft?

Author:  DtY [ Fri Aug 28, 2009 3:15 pm ]
Post subject:  RE:Obfuscated Code Contest

Oh, mine didn't actually work >_<
I think I know what I did wrong though

Author:  DtY [ Fri Aug 28, 2009 3:29 pm ]
Post subject:  RE:Obfuscated Code Contest

Okay, I can't get it to get the right answer, and I have a feeling it has to do with my output, oh well, here's my code that seems to be giving the right solution, but is being marked wrong:

c++:
#include <stdio.h>
#include <string.h>

void r(int t) {
    int c;
    int i=1;
    if (t>0)
        r(t-1);
   
    while ((c = getchar()) != 92) {
        if (strchr("KGF", c))
            i *= 2;
        if (c==82)
            i *= 3;
    }
    printf("%d\n",i);
}

main(void) {
    r(9);
}


$ cat main.c | tr -d [:space:] | wc -c
168

[edit] Code tags not working, what'd I do wrong?
[mod edit] Use syntax tags

Author:  bbi5291 [ Fri Aug 28, 2009 3:32 pm ]
Post subject:  Re: Obfuscated Code Contest

I think you've misunderstood the problem statement. Read it again carefully.

Author:  saltpro15 [ Fri Aug 28, 2009 3:41 pm ]
Post subject:  Re: Obfuscated Code Contest

alright, here's mine : 103 bytes

It's basically just a conversion of my Ruby one (43 bytes)

Compiles and AC's on the Sphere Judge

edit : ok, in truth I've been working on this problem for about 2 weeks, so I'm disqualifying myself from the contest.

Author:  DtY [ Fri Aug 28, 2009 3:53 pm ]
Post subject:  Re: Obfuscated Code Contest

bbi5291 @ Fri Aug 28, 2009 3:32 pm wrote:
I think you've misunderstood the problem statement. Read it again carefully.

Maybe I didn't think this through enough, but it works with the example: it sets the number of possibilities to one, and then iterates over each character, if it's one of K, G or F the number of possibilities doubles because there are two letters each of those could mean, if it's an R the number of possibilities triples because there are three letters that could mean. It worked on paper.. I guess I'll have to take a close look later.

Author:  saltpro15 [ Fri Aug 28, 2009 4:04 pm ]
Post subject:  RE:Obfuscated Code Contest

edit : ok what the hell?

My code's 104 bytes, not 103...

Author:  bbi5291 [ Fri Aug 28, 2009 4:33 pm ]
Post subject:  Re: Obfuscated Code Contest

It could be a Windows/*nix thing.

Author:  saltpro15 [ Fri Aug 28, 2009 5:14 pm ]
Post subject:  RE:Obfuscated Code Contest

I think it is...

woo, I just realized my code is the same size as Hanson's Very Happy

my hints to people :
Spoiler:

hint 1: scanf("%*[^DFLT\n]")
hint 2: you don't need a return 0;

Author:  A.J [ Fri Aug 28, 2009 7:50 pm ]
Post subject:  RE:Obfuscated Code Contest

This isn't actually what I meant.

I meant for an 'Obfuscated Code Contest', where points are given to the most creatively obfuscated code.

Author:  OneOffDriveByPoster [ Sat Aug 29, 2009 12:09 am ]
Post subject:  Re: Obfuscated Code Contest

Got one in for 94 with C (not quite as good as the 64 some people got).
http://www.spoj.pl/status/driveby_poster/

My hints to people:
Spoiler:

Hint 1: strchr
Hint 2: You don't need "int".

Author:  A.J [ Sat Aug 29, 2009 11:39 am ]
Post subject:  RE:Obfuscated Code Contest

I think someone ought to change the title of this thread to something else, as the word 'obfuscated' might mislead them.


: