[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1314.0. "Obfuscated C" by JARETH::EDP (Always mount a scratch monkey.) Mon Oct 22 1990 15:41

    There is an annual contest for Obfuscated C programs.  Entries must be
    1536 characters or less.  Winning programs are selected in entries such
    as "Worst Abuse of the Preprocessor" and "Strangest Looking Program".
    
    Some of the programs are of mathematical interest.  I will post them in
    replies to this topic.
    
    
    				-- edp
T.RTitleUserPersonal
Name
DateLines
1314.1JARETH::EDPAlways mount a scratch monkey.Mon Oct 22 1990 15:5255
    Arch D. Robison at the University of Illinois wrote the following
    program.  It uses only a few variables and one array and prints up to
    256 digits of e in a specified base.  The only arithmetic used is
    decrementing and comparison.  (The description that accompanied the
    contest results implied there is a bug; invoke the program with 80
    digits in base 2.)  This and other C programs can be invoked by
    defining a DCL symbol:  "symbol = $file_specification" and then typing
    the symbol followed by the arguments.  The file specification must
    include a disk name.  This program's arguments are the number of digits
    followed by the base.  Both default to 10.
    
    
    				-- edp
    
    
#include <stdio.h>
unsigned char w,h,i,l,e,x,y=10,z=10,F[256];
#define whi1e(j,k)  printf(j,k); fflush(stdout)
#define o F[w]

main	(c,v)	char *v[]; {
while	(c>=2	){z = atoi(v[1]),--c;
while 	(c>=2	)y = atoi(v[2]),--c;}
whi1e	("%s"	,"2.");
while	(--y)	--x;
while	(--x)	--e,--y;
while	(--z)	--x;
while	(--x)	--e,--z;
while	(--w)	{
while	(--x)	--o;}
while	(--z)	{
while	(--x)	--w;
while	(--o)	;
while	(--w)	;
while	(--e)	--x;
while	(--x)	--w,--e;
while	(--w)	{
while	(--l)	;
while	(--i)	--l;--l;
while	(--h)	;
while	(--y)	--x;
while	(--x)	--h,--y;
while	(--x)	--h;
while	(--h)	{
while	(--o)	--x;
while	(--x)	--l,--o;
while	(l>=w	){--i;
while	(--w)	--l,--x;
while	(--x)	--w;--l;}}
while	(--o)	;
while	(--l)	--x;
while	(--x)	--o;}
while	(--i)	--h;
whi1e	("%x"	,--h);--e;}
whi1e	("%s"	,"\n");}
1314.2JARETH::EDPAlways mount a scratch monkey.Mon Oct 22 1990 16:02127
    This program by Adrian Mariano at the University of Washington won
    "Best of Show" in 1990.  It implements four functions.
    
    The first function is:
    
            $theorem expression x1 x2 h y1
    
            where:
                    expression - function f(x,y)  (see below)
                    x1 - start of interval
                    x2 - end of interval
                    h - step size
                    y1 - initial value  (y(x1) == y1)
    
    When you compile theorem.c as is and run with 5 args, it numerically
    solves the equation y'=f(x,y), with a step size of h, over the interval
    x=[x1,x2], with the initial condition of y(x1)=y1.  (The Runge-Kutta
    method is used.)
    
    The 'expression' f(x,y), is any function of 'x' and 'y' with the
    operators:
    
                    +       -       *       /   ^
    
    Invoked with "$theorem -r 0 0 0 0", it reverses its input, line by
    line.  If the source is reversed, compiled, and executed, the result is
    a program that sorts its input.  And if the source is sorted, compiled,
    and executed, the result is a program that generates Fibonacci
    sequences.
    
    
    				-- edp
    
    
#include <stdio.h>
#include <math.h>
#define X
#define Y {}
#define C  }
#define o {
#undef main
char m[500][99],v[99],R;
int*a,b,n,i,j,W,A;
float Q,G,D,M,T,B,O,U,V,N,y,e();
P(g,R,u)float*g,R,u;{int c;for(*g=1,c=u;c--;*g*=R);}
X
K(g,R,u)float*g,u;char R;
o
if(R=='+')*g+=u;
if(R=='-')*g-=u;
if(R=='*')*g*=u;
if(R=='/')*g/=u;
if(R=='^')P(g,*g,u);
C
w(g,R,u)float*g,u;char R;
/**/{int b,f;A=atoi(*++a);b=atoi(*++a);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}
main(A,a)int A;char*a[];
o o
if(!strcmp(*++a,"-r"))S();
D=atof(*++a);
T=atof(*++a);
B=atof(*++a);
M=atof(*(4+(a-=3)));
C
while(D<T)
o
U=e((G=B/2,*a),D,M,a);
V=e(*a,Q=D+G,M+G*U,a);
/*/
z;/*/
N=2*e(*a,Q,M+G*V,a);
M+=B*V/3+B*N/6+B*e(*a,D+=B,M+G*N,a)/6+G*U/3;
printf("%f %f\n",D,M);
C
while(T=0)
;
W=D=1;
;
while(W!=1)
o o
strcpy(j+m,v);
o 
if((j-=W)<=W)break;
strcpy(j+m,m+j-W);
C
while(strcmp(m+j-W,v)>0)
j=i;
strcpy(v,i+m);
C
for(i=(W/=3)-1;++i<n;)
;
C
do
;
while(0);
for(W=1;(W=W*3+1)<n;);
C
float e(f,D,M,a)char*f,*a[];float D,M;
o
#define main L
O=0;
R='+';
for(;*f;f++)
if(*f=='y')K(&O,R,M);
else if((*f>='0')&&(*f<='9'))K(&O,R,(float)*f-'0');
else if(*f=='x')K(&O,R,D);
else if(1)R=*f;
if(1);
return O;
for(j=0;j<n;puts(j++[m]));
e("",O,&O,a);
n=j-(O=1);
while(gets(j++[m]));
if(!strcmp(*++a,"-r"))S();
C
/**/main(A,a)int A;char*a[];
Y
S(){while(gets(b++[m]));for(b--;b--;puts(b[m]));}
char*f,m[500][99],R,v[99];
int b,W,n,i,j,z;
float Q,G,D,M,T,O,B,U,V,N,e();
#define Y
#define X {}
#define o }
#define C {
#include <stdio.h>
#include <math.h>
1314.3JARETH::EDPAlways mount a scratch monkey.Mon Oct 22 1990 18:5915
    Doron Osovlanski (CADTECH, Israel) and Baruch Nissenbaum (Tel-Aviv
    University) wrote this program which solves the N-Queens problem.  N is
    passed in the input.  This program uses no pre-processor statements, no
    ifs, no breaks, no cases, no functions, no gotos, and only a single for
    statement.


    				-- edp


    v,i,j,k,l,s,a[99]; main() {	
    for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!
    printf(2+"\n\n%c"-(!l<<!j),"#Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&
    v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i])		
    ; }
1314.4HAKMEM #169DECWET::BISHOPNihon ga natsukashii ...Mon Oct 22 1990 20:2125
/*

This routine was invented to do something useful and do it very efficiently.
I enter it here because the algorithm is so obscure as to be almost 
undecipherable.  Can anyone figure out what it does?  I blanked out the descrip-
tion and changed names and variables so as not to give it away.

Avery

*/

    
int
dummy(mask)
int	mask;
{    
    int dum;

    /* next 3 magic statements AAAAAAAAAAAAAAAAA (HAKMEM #169) */
    dum = (mask >> 1) & 033333333333;
    dum = mask - dum - ((dum >> 1) & 033333333333);
    dum =  (((dum + (dum >> 3)) & 030707070707) % 077);
    return dum;
}

1314.5number of OnesKAZAN::CHALEATWed Oct 31 1990 08:577
    
    This routine counts the number of ONEs in a binary string ?
    I did not figure why or how !
    Very clever.
    Useful when dealing with PCM.
    Marcel
    
1314.6?EAGLE1::BESTR D Best, sys arch, I/OWed Oct 31 1990 14:286
re .-1

>...
>    Useful when dealing with PCM.
                              ^
Pulse code modulation ?
1314.7? yes:no;KAZAN::CHALEATMon Nov 05 1990 08:322
    you are right !
    I was thinking to delta modulation.
1314.8ELIS::GARSONV+F = E+2Tue Feb 12 1991 09:006
    re .3
    
>    Doron Osovlanski (CADTECH, Israel) and Baruch Nissenbaum (Tel-Aviv
>    University) wrote this program which solves the N-Queens problem.
    
    What is the N-queens problem?
1314.9GUESS::DERAMODan D'EramoTue Feb 12 1991 13:268
        re: What is the N-queens problem?
        
        Take a "generalized chess board" of size n x n instead of
        8 x 8, and place n queens on it so that none of them is
        attacking any of the others.
        
        Dan
        
1314.10ELIS::GARSONV+F = E+2Tue Feb 12 1991 14:194
    re .-1
    
    That's what I would have guessed but the program in .3 does not appear
    to do this. Can someone verify this?