473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how this program works

Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really.
can anyone tell.
thanks
cric

#include <stdio.h>
main(int t,char _,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;# ){n\
l]!/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(a[31]):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);}
Nov 14 '05 #1
10 1986
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.

"free2cric" <fr*******@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really.
can anyone tell.
thanks
cric

Nov 14 '05 #2

aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...

Tom

Nov 14 '05 #3

"Tom St Denis" <to********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

GNU indent didn't like it neither.

I think it just isn't valid C code...

Could be a code written for some old, pre-ansi
compiler. Of course, if the original poster was
able to compile and run this code, s/he should've
posted the compiler and instructions.
Nov 14 '05 #4
"Tom St Denis" <to********@gmail.com> wrote:
aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...


With a declaration like main(int t,char _,char *a)? I think it's safe to
say that it's nowhere near valid, let alone portable, C code.

Richard
Nov 14 '05 #5

free2cric wrote:
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really. can anyone tell.
thanks
cric


Yes, I remeber this program. It is valid and it compiles fine with
GCC, even though it generates plenty of warnings. I *think* it works
by having a obscure string, do some operations on it to make it into
the lyrics, name it a obscure name, delete all the white space, print
the different substring of the string, and use recursion to print the
whole thing.

This program uses recursion to print one of the most famous Christmas
songs, "Twelve Days of Christmas".

The output of the program is:

"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
sevean 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 eig hth day of Christmas my true love gave to me
eight maids a-milking, sevean 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, sevean 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, sevean 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, sevean 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, sevean 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."

You have to admit, whoever wrote the program was pretty good.

Nov 14 '05 #6
Tom St Denis wrote:
aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...


[1] c:\c\junk>cc obfusc.c
obfusc.c:3: warning: return type defaults to `int'
obfusc.c:3: warning: second argument of `main' should be `char **'
obfusc.c:3: warning: third argument of `main' should probably be
`char **'
obfusc.c: In function `main':
obfusc.c:6: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:7:3: warning: multi-line string literals are deprecated
obfusc.c:7:3: warning: unknown escape sequence: '\040'
obfusc.c:7: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:14: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:14: warning: passing arg 3 of `main' discards qualifiers
from pointer target type

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #7
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
What is obscure string.
Can someone tell in more detail. Its interesting. We can all get benefit of.
thanks cric.

"Steven" <so******************@yahoo.com> wrote in message news:<11*********************@o13g2000cwo.googlegr oups.com>...
free2cric wrote:
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works

really.
can anyone tell.
thanks
cric


Yes, I remeber this program. It is valid and it compiles fine with
GCC, even though it generates plenty of warnings. I *think* it works
by having a obscure string, do some operations on it to make it into
the lyrics, name it a obscure name, delete all the white space, print
the different substring of the string, and use recursion to print the
whole thing.

This program uses recursion to print one of the most famous Christmas
songs, "Twelve Days of Christmas".

The output of the program is:

"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
sevean 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 eig hth day of Christmas my true love gave to me
eight maids a-milking, sevean 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, sevean 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, sevean 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, sevean 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, sevean 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."

You have to admit, whoever wrote the program was pretty good.

Nov 14 '05 #8
"free2cric" <fr*******@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
My VC++6.0(SP6) rejected it (but perhaps it got
distorted by my newsreader).
What is obscure string.
It's in the code. Actually there are two strings
(not counting the two 'printf()' format strings):

"@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;# ){n\
l]!/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' ')# }'+}##(!!/"

and

"!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"
Can someone tell in more detail.
Tell what.
Its interesting.
Perhaps it is to some. I suggest that if you want to
figure out how it works, do one or both of:

1. Work through it with pencil and paper.

2. Watch it with a debugger. (this might involve obtaining
an implementation that doesn't reject the language
violations.)
We can all get benefit of.


Some might, others not. It could also cause some
to believe it's valid code.

BTW please don't top-post in comp.lang.c. Thank you.

-Mike
Nov 14 '05 #9

"free2cric" <fr*******@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
What is obscure string.
Can someone tell in more detail. Its interesting. We can all get benefit of. thanks cric.


I just tried VC++ 6.0 and no got even more errors than with BC++ 5.02.
In any case, if you look at the code, it's recursively calling main()
depending
on "t", end at the end, it does a putchar(). It shouldn't take more than a
few
hours with a debugger to figure out "exactly" how it works, but I kinda
doubt that anyone will do it for you. ;-)
Nov 14 '05 #10
BTW, a quick search revealed that there's a version at:
http://www.ioccc.org/1988/phillipps.c
that compiles and runs fine. Neat program.
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
6
by: William J. Leary Jr. | last post by:
I'm running a VB6 program, the IDE for a compiler. Paste doesn't work if the text was cut/copied from within the program. That is: 1. Cut/copy inside the program, can't paste. Program:...
7
by: jan.dostrasil | last post by:
Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;) I have a program in c which is working fine, it reads everything from pipe, modifies...
23
by: JoeC | last post by:
I am a self taught programmer and I have figured out most syntax but desigining my programs is a challenge. I realize that there are many ways to design a program but what are some good rules to...
5
by: Igor | last post by:
Hi! We built VB6 application to work with Reporting Services server. To connect to reporting server has been created a special assembly with .NET VS2003. While we execute our program on local...
27
by: Neil | last post by:
Hello all! I wrote program with a array of pointers, and I suspect they are pointing at each other in the Do ...While loop. Something is messed up with the increment variable word. A program...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
0
by: bvdb | last post by:
Hi Everyone, One of my customers lives in Taiwan and can only make my program work if he changes his Regional and Language Options to English from the Simplifies Chinese that his computer is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.