One little program

Discussion around programming R'n'D, its source code and its tools.

Moderators: Zomis, Flumminator

Post Reply
Tomi
Posts: 339
Joined: Wed Aug 03, 2005 3:37 pm
Location: Slovakia

One little program

Post by Tomi » Fri Dec 02, 2005 2:47 pm

I know this isn't related to RnD, so it should belong to Off Topic, but there's no "Off Topic Programmer's Corner" :) and I think Programmer's Corner suits this better than Off Topic. Well, this is it - my newest piece of programming art:

Code: Select all

#include <stdio.h>
main(a,b)
{return b==982?main(127,a<79?main(a+1,982):128):a==51?72:a>
127?a>130?a:a==129?32:b-127:a==127?main(a+3,a+b):a==63?127-
b:a<10?main(11,98):a==76?main(51,putchar(main(41,b))):a==58
?main(b+main(63,b),b*(66+b)):a==12?main(main(2,982)-1,main(
76,b)):a<12?main(127,main(51,main(89,-2))-72):a==89?main(129
,b>10?127:main(main(89,b+1)+95,main(12,b+2))):a==41?main(b/
2+a+a,b):a>80?a<83?main(a+45,main(51,b+127)+b*29):a==84?427-
79*b:a<=83?108:a==87?main(58,11-b)+33:a<=85?119-(b-6)*8:a>86
?main(51,a)-62:b==8?main(15,83):main(83,15):114;
}
gcc -o nameless.exe nameless.c
No malicious code included (it uses just putchar). You may get some warnings however (implied type of a,b etc.) Try to guess what it does. :wink:

User avatar
Holger
Site Admin
Posts: 3225
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Post by Holger » Fri Dec 02, 2005 5:07 pm

Very nice! :-)

Also try this one:

Code: Select all

float s=1944,x[5],y[5],z[5],r[5],j,h,a,b,d,e;int i=33,c,l,f=1;int g(){return f=
(f*6478+1)%65346;}m(){x[i]=g()-l;y[i]=(g()-l)/4;r[i]=g()>>4;}main(){char t[1948
]=" `MYmtw%FFlj%Jqig~%`jqig~Etsqnsj3stb",*p=t+3,*k="3tjlq9TX";l=s*20;while(i<s)
p[i++]='\n'+5;for(i=0;i<5;i++)z[i]=(i?z[i-1]:0)+l/3+!m();while(1){for(c=33;c<s;
c++){c+=!((c+1)%81);j=c/s-.5;h=c%81/40.0-1;p[c]=37;for(i=4;i+1;i--)if((b=(a=h*x
[i]+j*y[i]+z[i])*a-(d=1+j*j+h*h)*(-r[i]*r[i]+x[i]*x[i]+y[i]*y[i]+z[i]*z[i]))>0)
{for(e=b;e*e>b*1.01||e*e<b*.99;e-=.5*(e*e-b)/e);p[c]=k[(int)(8*e/d/r[i])];}}for
(i=4;i+1;z[i]-=s/2,i--)z[i]=z[i]<0?l*2+!m():z[i];while(i<s)putchar(t[i++]-5);}}
It's not by me, but can be found here: http://www.ioccc.org/1996/eldby.c

Tomi
Posts: 339
Joined: Wed Aug 03, 2005 3:37 pm
Location: Slovakia

Post by Tomi » Fri Dec 02, 2005 5:39 pm

That one is nice too... however, I had other goal when creating the one above - to make a program which would have just main() with one return, contain no string and be protected against debugging. (Seriously! It contains a *long* idle loop, called several times!)
This one (not by me) is definitely the best though:

Code: Select all

#include <stdio.h>
main(t,_,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(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);
}
I've studied a bit and found some way to get a "On the ,first,second,third,..." data string out of it, but how does it do it remains a mystery. A pity that I don't know who made it.

User avatar
Holger
Site Admin
Posts: 3225
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Post by Holger » Fri Dec 02, 2005 7:02 pm

Really cool... :-o

Zomis
Posts: 1501
Joined: Mon Jun 21, 2004 1:27 pm
Location: Sweden
Contact:

Post by Zomis » Sun Dec 11, 2005 12:49 pm

I seriously have no idea what these does, but maybe you can see:
Taken from: http://www.gamedev.net/reference/articl ... le1637.asp

Code: Select all

int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c
-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}

Code: Select all

char*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C);
--            E;             J[              E]             =T
[E   ]=  E)   printf("._");  for(;(A-=Z=!Z)  ||  (printf("\n|"
)    ,   A    =              39              ,C             --
)    ;   Z    ||    printf   (M   ))M[Z]=Z[A-(E   =A[J-Z])&&!C
&    A   ==             T[                                  A]
|6< <11<rand()||!C&!Z?J[T[E]=T[A]]=E,J[T[A]=A-Z]=A,"_.":" |"];}

User avatar
Francesco
Posts: 577
Joined: Thu Dec 29, 2005 2:22 pm
Location: Sardinia (Italy)
Contact:

Post by Francesco » Thu Feb 09, 2006 11:19 pm

Cool! If learning C would mean to manage things like the above, I seriously need to find a rope to hang myself from the ceiling... :wink:

(you don't really need to consider this post, I'm just taking a walk in these Turkish threads... :wink: )
Anyway, by the way, have fun!
Francesco

User avatar
Holger
Site Admin
Posts: 3225
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Post by Holger » Fri Feb 10, 2006 8:34 pm

Don't worry -- I probably could never write or understand such programs... It would take too much time which I would better like to spend on other things. :-)

But it looks crazy and it's always nice to see that it actually does something! :-)

Tomi
Posts: 339
Joined: Wed Aug 03, 2005 3:37 pm
Location: Slovakia

Post by Tomi » Fri Jun 20, 2008 6:25 pm

Long time no see!

I know this is an old topic, but I felt it's better to post this here, instead of starting a new one. I've made another program, similar to the other ones in that the whole program body is in one 'return' statement. However, this one is actually interactive.

IMPORTANT: This won't work on Windows. See below.

Code: Select all

#define _ main
#include <stdio.h>
#define clrscr() printf("\e[H\e[2J")
int _(int t,int p,int a){return-1==t?p+_(-9,_(-3,p,-2),0)==a?0:_(t,_(-10,p,t),a
):t==-16?p>95?p-71:p>60?p-65:p<44?p+19:p>47?p+4:p+16:t==35018?60:t>=0?t<34640?_
(-1,4128831,0):t%40==38?32:t==35019?62:t%40==39?10:_(-10-4,p+t/2%20-9+(t/40-866
-9<<16),a)?32:35:t==-10?_(t-1,getchar(),p):t==-3?_(-9,clrscr(),0)?a:_(a,p,34640
):t==-13?_(t-1,p+a,a)?p+a:p:t==-11?_(t-1,a,p>92?p-109:p-77):t==-2?a>=35400?0:_(
-9,putchar(_(a,p,a)),0)?p:_(t,p,a+1):t==-15?_(t-1,_(t*2,a,p/6),a)&_(p%6-9,2,1):
t>-9?_(t-1,p,a*p):t==-14?p>>16<0||p>>16>=64||(p&65535)>=64?0:_(t-1,(p&65535)+(p
>>16)*64,a):t==-9?a:t==-12?_(t-1,p,a==10?-65536:a==-9?1:a==-12?-1:a==6?65536:0)
:"1/Xj37/92vbXAvNnCy5GtX1HyNa/qZ+WXV+l+l028oeT1i9y764wzWXXPwhzZ5F1TGexzH35L9Zn\
O0mpeSrclX++mypwWcJLeV6uR73uxf7aua1Xh2mTqW72VL2r2ubvvSzuemqqkTcqtzcs46uX3t1l1V\
NVZUd02rPr19+176GrWuzjaVlabjWNGT/sdrdrcXeXW4sg2YvVeN+8p9d3FOuq+ywWitmv1afR3Vtr\
WNeXdtdr3ma9da+o2NnG7VQVq6f1abj19b/qB1qrt1moK2z32pO2r+57VVzUzUr20Fb7i2t1XL3wev\
4ZnWnsOb5q60FaLrNO9R/5W/jOvd+SPpJlKtusNYW+vvb8d62+dVYWqFh5VF0c9d7W73V372a1q1uJ\
xEqrmq5Dr09r/Vbvurv8zqCRPtsKD6qbsvV9tyevYItFtphtbt6l7WftrXmzaRPbt4uKtAn9tcatUs\
2au2Vd1za/qq94p70m2dk6W15NyZsk5tUN129l86tya1arrV9olqwVrquVblmubXt6bkXSffmdauK7\
v4Ohsu476dZYj21u8qYR53tO2bp525ZprtcrzrV3y7brxVrjKO6CJnXmbH3y6x/uL8Wbe13qnoq8wW\
7QVmWt2e5bNz3efbd1dh1aXbMgb1143rapd8Vbo7TK7lj9ybdCU/eTvP6r79P"[a];}
To run this program, compile it and type:

Code: Select all

stty -icanon; ./programname; stty cooked
Then find the upper-left corner. Use WASD, not arrows.

(In "-icanon mode", getchar() doesn't wait for the Return key, and returns the code immediately after a character was typed.)
This version only works on Linux tty's. To port it to Windows, one should #include <conio.h>, replace getchar() with getch(), and re-implement clrscr(), probably with system("cls"), but that might be slow and I didn't test it. (Maybe printf("\n\n\n\n\n\n\n\n...\n\n\n") would work as well, by scrolling the old screen content, thus "clearing" it.)
(The standard DOS conio.h already has clrscr, so one could simply remove the #define clrscr. But the one shipped with MinGW doesn't.)

Post Reply