Jump to content

Crazy code


Marc

Recommended Posts

I was thinking about this the other day and decided to look it up...

Anyone who has the gumption to try this,

#include <stdio.h>
main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
}'+}##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

Compile and run that hunka code and you'll be pleasantly surprised.

Ciao

Marc

P.S. And I don't mean pleasantly surprised by a disk crash or something... I mean pleasantly surprised in a 'wow, thats cool' kinda way :P

P.P.S I just tried it and there were some warnings, but it still worked.

Link to comment
Share on other sites

Ok guys, for those of us who don't compile, what the heck does it do  :blink:

WARNING: SPOILER!!!

It prints out the following:

On the first day of Christmas my true love gave to me
a partridge in a pear tree.

On the second day of Christmas my true love gave to me
two turtle doves
and a partridge in a pear tree.

On the third day of Christmas my true love gave to me
three french hens, two turtle doves
and a partridge in a pear tree.

On the fourth day of Christmas my true love gave to me
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the fifth day of Christmas my true love gave to me
five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the sixth day of Christmas my true love gave to me
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the seventh day of Christmas my true love gave to me
seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eigth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eleventh day of Christmas my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the twelfth day of Christmas my true love gave to me
twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

Cute, huh? :)

Link to comment
Share on other sites

Hehe :P

So; are you thinking about entering this year's IOCCC contest?

Thanks Marc. That was fun :)

Actually, this one was 1988's winner of the ioccc contest. I remember being fresh out of college and being awestruck by it. Now here I am 10 years later and I'm still in the same boat.. :P .

Link to comment
Share on other sites

Now here I am 10 years later and I'm still in the same boat..  :P .

Yup. WAY KEWL stuff.

I looked at it a little more, and even if I ignore all the string obfuscation (my gut tells me they are ascii offsets, with each offset passed in as the arguments that would normaly be argc and argv [?]), I *still* can't even get past the first statement!

I mean... How the heck is this legal C code?!

main(t,_,a)char *a;
{
}

It would never make it through a C++ compiler, but just *how* is main(t,_,a)char * a type ?!? If you remove the pointer-to-char, then it's just the definition of main() (one that can get through a C-compiler at least). But then what role does the char * play? Is it some obscure syntax to force main() to have a return type that is not int? (i.e: a screwd up way to type-cast main() ??? )

And since when does main() take *3* arguments (one of them being "_") ?!?

... and yet the compiler swallows it all with barely a complaint... crazy stuff...

Any clues ?

Link to comment
Share on other sites

I got curious and just wanted to find out how many unique words where in the poem, and look st at this:

On the first day of Christmas my true love gave to me a partridge in pear tree. second two turtle doves and third three french hens fourth four calling birds fifth five gold rings; sixth six geese a-laying seventh seven swans a-swimming eigth eight maids a-milking ninth nine ladies dancing tenth ten lords a-leaping eleventh eleven pipers piping twelfth twelve drummers drumming

Thats 62 unique words from the full 425.

I guess herein lies the secret of COMPRESSION. :ph34r:

Link to comment
Share on other sites

Thats 62 unique words from the full 425.

I guess herein lies the secret of COMPRESSION. :ph34r:

B)

You are right, of course, but a listing of the unique words is not the same as the poem. So you'd still need to encode the rules that use those words to make sentences, add punctuation, split them into 12 paragraphs, etc. etc.

Having said that, the source code before compilation is 817 bytes long, whereas a gzipped version of the entire formatted output is only 317 bytes... so no; it doesn't get any medals for compression :P

But it *is* a very impressive example of obfuscation; you gotta admit. This thing is pretty damn hermetic (to me at least). I was just wondering if there was an online copy of the ansi-c standard somewhere... that main() declaration is driving me nuts! <_<

Off I go to google land...

Link to comment
Share on other sites

I mean... How the heck is this legal C code?!

main(t,_,a)char *a;
{
}

It's using K&R old-style C declarations. I probably still have a copy down in the basement somewhere. Everything probably defaults to int for the untyped stuff. So filling for this, the more recognizeable style would be:

int main(t, _, a)
int t;
int _;
char *a;
{
}

New style would be:

int main(int t, int _, char *a)
{
}

Of course, we're still not ANSI C yet that's not the standard declarction for main().

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...