
-----------------------------------
saltpro15
Fri Aug 28, 2009 2:37 pm

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 [url=http://www.spoj.pl/problems/KAMIL/]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

-----------------------------------
DtY
Fri Aug 28, 2009 2:43 pm

RE:Obfuscated Code Contest
-----------------------------------
Can we use C since you can compile C as C++?

-----------------------------------
saltpro15
Fri Aug 28, 2009 2:51 pm

RE:Obfuscated Code Contest
-----------------------------------
sure

-----------------------------------
bbi5291
Fri Aug 28, 2009 2:52 pm

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 .

-----------------------------------
saltpro15
Fri Aug 28, 2009 2:56 pm

RE:Obfuscated Code Contest
-----------------------------------
good ideas Brian.  Unfortunately I can't edit my post on this forum...

-----------------------------------
DtY
Fri Aug 28, 2009 3:10 pm

RE:Obfuscated Code Contest
-----------------------------------
Okay, I got 164 bytes following bbi5291's rules. Gonna see if I can shave off a little more :)

-----------------------------------
bbi5291
Fri Aug 28, 2009 3:12 pm

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.

-----------------------------------
saltpro15
Fri Aug 28, 2009 3:13 pm

RE:Obfuscated Code Contest
-----------------------------------
my best so far is 43 bytes with Ruby... I'll try it in C++

-----------------------------------
bbi5291
Fri Aug 28, 2009 3:15 pm

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?

-----------------------------------
DtY
Fri Aug 28, 2009 3:15 pm

RE:Obfuscated Code Contest
-----------------------------------
Oh, mine didn't actually work >_<
I think I know what I did wrong though

-----------------------------------
DtY
Fri Aug 28, 2009 3:29 pm

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:

#include 
#include 

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 [] | wc -c
168

[edit] Code tags not working, what'd I do wrong?
[mod edit] Use syntax tags

-----------------------------------
bbi5291
Fri Aug 28, 2009 3:32 pm

Re: Obfuscated Code Contest
-----------------------------------
I think you've misunderstood the problem statement. Read it again carefully.

-----------------------------------
saltpro15
Fri Aug 28, 2009 3:41 pm

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.

-----------------------------------
DtY
Fri Aug 28, 2009 3:53 pm

Re: Obfuscated Code Contest
-----------------------------------
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.

-----------------------------------
saltpro15
Fri Aug 28, 2009 4:04 pm

RE:Obfuscated Code Contest
-----------------------------------
edit : ok what the hell?  

My code's 104 bytes, not 103...

-----------------------------------
bbi5291
Fri Aug 28, 2009 4:33 pm

Re: Obfuscated Code Contest
-----------------------------------
It could be a Windows/*nix thing.

-----------------------------------
saltpro15
Fri Aug 28, 2009 5:14 pm

RE:Obfuscated Code Contest
-----------------------------------
I think it is...

woo, I just realized my code is the same size as Hanson's :D

my hints to people :

hint 1: scanf("%*

-----------------------------------
A.J
Fri Aug 28, 2009 7:50 pm

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.

-----------------------------------
OneOffDriveByPoster
Sat Aug 29, 2009 12:09 am

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:

Hint 1:  strchr
Hint 2:  You don't need "int".


-----------------------------------
A.J
Sat Aug 29, 2009 11:39 am

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.
