Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Obfuscated Code Contest
Index -> Programming, C++ -> C++ Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
saltpro15




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Fri Aug 28, 2009 2:43 pm   Post subject: RE:Obfuscated Code Contest

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




PostPosted: Fri Aug 28, 2009 2:51 pm   Post subject: RE:Obfuscated Code Contest

sure
bbi5291




PostPosted: 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.
saltpro15




PostPosted: 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...
DtY




PostPosted: 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
bbi5291




PostPosted: 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.
saltpro15




PostPosted: 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++
Sponsor
Sponsor
Sponsor
sponsor
bbi5291




PostPosted: 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?
DtY




PostPosted: 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
DtY




PostPosted: 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
bbi5291




PostPosted: 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.
saltpro15




PostPosted: 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.



untitled.bmp
 Description:
 Filesize:  350.68 KB
 Viewed:  273 Time(s)

untitled.bmp


DtY




PostPosted: 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.
saltpro15




PostPosted: 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...
Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: