Move 1988-2004 entries into subdirs

We we move 1988-2004 entries from all of a year's winning entries
in a single directory to each winner being in their own sub-directory
under the given year directory.
This commit is contained in:
Landon Curt Noll committed 2022-09-18 23:37:49 -07:00
1 parent 1e82e8aa3e
commit d2a42f42e8
478 files changed

No files matched your search

+130
View File
@@ -0,0 +1,130 @@
#include<stdio.h>
/* $Id: hunni.c,v 1.5 1996/11/17 20:58:04 schweikh Exp schweikh $ */
/* usage: hunni [n_op [start [increment [goal]]]] */
/* Up to 20! = 2432902008176640000 */
/* < 9223372036854775807 = 2^63-1 */
/* n! fits in signed long long ints, */
/* with 19 operators there are 4^19 = 274,877,906,944 combinations, */
/* up to 12! = 479001600 */
/* < 2147483647 = 2^31-1 */
/* n! fits in signed long ints, */
/* with 11 operators there are 4^11 = 4,194,304 combinations. */
/*@-loopswitchbreak@*/
/*@-protoparamprefix p_@*/
/*@-pointerarith@*/
/*@+ignorequals@*/
#define FMT "%ld" /* printf and scanf format for this type */
#define LONGEST long /* longest type of this implementation */
typedef struct { LONGEST num, den; } fraction;
typedef unsigned LONGEST bitvec;
static fraction init[20], work[20], param[4] = {
{ 9, 1 } ,
{ 1, 1 } ,
{ 1, 1 } ,
{ 6 * 7, 1 }
};
static int J;
static void
out (fraction f)
{
if (f.den - 1) {
J = printf (FMT "/" FMT, f.num, f.den);
} else {
J = printf (FMT, f.num);
}
}
static void
normalize (fraction *p_f)
{
LONGEST a = (*p_f).num, b = (*p_f).den;
if (b) {
while (a) {
LONGEST i = b % a;
b = a;
a = i;
}
b = b < 0 ? - b : b ;
(*p_f).num /= b;
(*p_f).den /= b;
}
}
int
main (int argc, char *argv[])
{
bitvec m, mask;
int i, cursor;
for (i = 1; i < 5; i = i + 1) {
if (argc > i) {
J = sscanf (argv[i], FMT "/" FMT,
&param[i-1].num, &param[i-1].den);
}
normalize (param + i - 1);
}
init[0] = param[1];
for (i = 0; i < param[0].num; i = i + 1) {
init[i+1].num = init[i].num * param[2].den
+ param[2].num * init[i].den;
init[i+1].den = init[i].den * param[2].den;
normalize (init + i + 1);
}
for (mask = ~(~0 << param[0].num*2); ~(bitvec)0 - mask; mask = mask - 1) {
/* Pass one computes mult and div. */
/* For add and sub the right operand is copied. */
work[cursor = 0] = init[0];
for (m = mask, i = 1; ! (i > param[0].num); i = i + 1, m = m / 4) {
if ((m & 3) < 2) {
if (m & 1) {
work[cursor].num *= init[i].den;
if ((work[cursor].den *= init[i].num) < 0) {
work[cursor].num *= -1;
work[cursor].den *= -1;
}
} else {
work[cursor].num *= init[i].num;
work[cursor].den *= init[i].den;
}
} else {
work[cursor = cursor + 1] = init[i];
}
}
/* Pass two computes the remaining adds and subs. */
for (m = mask, i = cursor = 0; i < param[0].num; i = i + 1, m = m / 4) {
if ((m & 3) > 1) {
work[0].num = work[0].num * work[cursor+1].den +
((m & 1) ? -1 : +1) * work[cursor+1].num * work[0].den;
work[0].den = work[0].den * work[cursor = cursor + 1].den;
}
}
normalize (work);
/* output result */
if (!param[3].den
|| (!(param[3].num - work[0].num)
&& !(param[3].den - work[0].den))) {
for (m = mask, i = 0; i < param[0].num; i = i + 1, m = m / 4) {
out (init[i]);
J = printf (" %c ", "*/+-"[m & 3]);
}
out (init[i]);
J = printf (" = ");
out (work[0]);
J = printf ("%c", 10); /* newline */
}
}
return J - 1;
}
+108
View File
@@ -0,0 +1,108 @@
#!/usr/bin/perl
#
print "#define C \" \"\n";
print "#define O( _ ) # _\n";
print "#define R( n , d ) e ( n , d )\n";
print "#define e(p,o)o##p\n";
print "#define D O ( % ) O ( l ) O ( d )\n";
print "#define U R ( e ( g , n ) , e ( o , l ) )\n";
print "#define M H ( R ( e ( c , i ) , t ) , R ( e ( a , t ) , s ) )\n";
print "#define P H ( R ( e ( f , t ) , n ) , R ( e ( i , r ) , p ) ) (\n";
print "#define H(O,r)R(O,r)\n";
print "#include<stdio.h>\n";
while (<>) {
chop;
s,/\*.*\*/,,g; # rm one line comments
s:([^a-z])int:$1R(e(t,n),i):g;
s:for:R(e(r,o),f):g;
s:main:R(e(n,i),e(a,m)):g;
s:([^a-z])char:$1R(e(r,a),e(h,c)):g;
s:printf \(:P :g;
s:void:R(e(d,i),e(o,v)):g;
s:else:R(e(e,s),e(l,e)):g;
s:while:H(R(e(e,l),i),e(h,w)):g;
s:struct:H(R(e(t,c),u),R(e(r,t),s)):g;
s:return:H(R(e(n,r),u),R(e(t,e),r)):g;
s:sscanf:H(R(e(f,n),a),R(e(c,s),s)):g;
s:typedef:H(R(e(f,e),e(d,e)),R(e(p,y),t)):g;
s:unsigned:H(R(e(d,e),e(n,g)),R(e(i,s),e(n,u))):g;
s,"/", O(/),g;
s,20,4*5,g;
s," = ",C O(=) C,g;
s," %c ",C O(%)O(c)C,g;
s,"%c",O(%)O(c),g;
s,"%ld",O(%)O(l)O(d),g;
s,"\*/\+-",O(*)O(/)O(+)O(-),g;
s,init,I,g;
s,param,p,g;
s,static,M,g;
s,work,w,g;
s,cursor,c,g;
s,normalize,n,g;
s,fraction,F,g;
s,num,n,g;
s,den,t,g;
s,LONGEST,U,g;
s,argc,a,g;
s,argv,v,g;
s,bitvec,B,g;
s,mask,W,g;
s,FMT,D,g;
s,p_f,f,g;
s,calc,k,g;
s,out,o,g;
s:10:e(0,1):g;
s:<<:e(<,<):g;
s:!=:e(=,!):g;
s:if:e(f,i):g;
s:\*=:e(=,*):g;
s:/=:e(=,/):g;
s:\|\|:e(|,|):g;
s:&&:e(&,&):g;
s:42:6*7:g;
s:(\S): $1 :g unless /^#/;
s:[ \t]+: :g;
s:^ ::;
s: $::;
unless (/^$/) {
$code .= "$_ " unless (/^#/);
}
}
chop $code;
$code =~ s/(.{31}) /$1\n/g;
@line = split (/\n/, $code);
for ($i = 0; $i <= $#line; ++$i) {
$_ = $line[$i];
$rem = $i % 8;
if ($rem == 0) {
s/(.{8})(.{8})(.{8})(.{7})/\t\1\t\2\t\3\t\4/;
} elsif ($rem == 1 || $rem == 7) {
substr ($_,1,1) = "\t";
substr ($_,7,1) = "\t";
substr ($_,9,1) = "\t";
substr ($_,15,1) = "\t";
substr ($_,17,1) = "\t";
substr ($_,23,1) = "\t";
substr ($_,25,1) = "\t";
} elsif ($rem == 2 || $rem == 6) {
substr ($_,3,1) = "\t";
substr ($_,7,1) = "\t";
substr ($_,11,1) = "\t";
substr ($_,15,1) = "\t";
substr ($_,19,1) = "\t";
substr ($_,23,1) = "\t";
substr ($_,27,1) = "\t";
} elsif ($rem == 3 || $rem == 5) {
substr ($_,5,1) = "\t";
substr ($_,7,1) = "\t";
substr ($_,13,1) = "\t";
substr ($_,15,1) = "\t";
substr ($_,21,1) = "\t";
substr ($_,23,1) = "\t";
substr ($_,29,1) = "\t";
} else {
s/(.{8})(.{8})(.{8})(.{7})/\1\t\2\t\3\t\4/;
}
print "$_\n";
}
+98
View File
@@ -0,0 +1,98 @@
#define C " "
#define O( _ ) # _
#define R( n , d ) e ( n , d )
#define e(p,o)o##p
#define D O ( % ) O ( l ) O ( d )
#define U R ( e ( g , n ) , e ( o , l ) )
#define M H ( R ( e ( c , i ) , t ) , R ( e ( a , t ) , s ) )
#define P H ( R ( e ( f , t ) , n ) , R ( e ( i , r ) , p ) ) (
#define H(O,r)R(O,r)
#include<stdio.h>
H ( R ( e ( f , e ) , e ( d , e
) ) , R ( e ( p , y ) , t ) ) H
( R ( e ( t , c ) , u ) , R ( e
( r , t ) , s ) ) { U n , t ; }
F ; H ( R ( e ( f , e ) , e ( d
, e ) ) , R ( e ( p , y ) , t )
) H ( R ( e ( d , e ) , e ( n ,
g ) ) , R ( e ( i , s ) , e ( n
, u ) ) ) U B ; M F I [ 4 * 5 ]
, w [ 4 * 5 ] , p [ 4 ] = { { 9
, 1 } , { 1 , 1 } , { 1 , 1 } ,
{ 6 * 7 , 1 } } ; M R ( e ( t ,
n ) , i ) J ; M R ( e ( d , i )
, e ( o , v ) ) o ( F f ) { e (
f , i ) ( f . t - 1 ) { J = P D
O ( / ) D , f . n , f . t ) ; }
R ( e ( e , s ) , e ( l , e ) )
{ J = P D , f . n ) ; } } M R (
e ( d , i ) , e ( o , v ) ) n (
F * f ) { U a = ( * f ) . n , b
= ( * f ) . t ; e ( f , i ) ( b
) { H ( R ( e ( e , l ) , i ) ,
e ( h , w ) ) ( a ) { U i = b %
a ; b = a ; a = i ; } b = b < 0
? - b : b ; ( * f ) . n e ( = ,
/ ) b ; ( * f ) . t e ( = , / )
b ; } } R ( e ( t , n ) , i ) R
( e ( n , i ) , e ( a , m ) ) (
R ( e ( t , n ) , i ) a , R ( e
( r , a ) , e ( h , c ) ) * v [
] ) { B m , W ; R ( e ( t , n )
, i ) i , c ; R ( e ( r , o ) ,
f ) ( i = 1 ; i < 5 ; i = i + 1
) { e ( f , i ) ( a > i ) { J =
H ( R ( e ( f , n ) , a ) , R (
e ( c , s ) , s ) ) ( v [ i ] ,
D O ( / ) D , & p [ i - 1 ] . n
, & p [ i - 1 ] . t ) ; } n ( p
+ i - 1 ) ; } I [ 0 ] = p [ 1 ]
; R ( e ( r , o ) , f ) ( i = 0
; i < p [ 0 ] . n ; i = i + 1 )
{ I [ i + 1 ] . n = I [ i ] . n
* p [ 2 ] . t + p [ 2 ] . n * I
[ i ] . t ; I [ i + 1 ] . t = I
[ i ] . t * p [ 2 ] . t ; n ( I
+ i + 1 ) ; } R ( e ( r , o ) ,
f ) ( W = ~ ( ~ 0 e ( < , < ) p
[ 0 ] . n * 2 ) ; ~ ( B ) 0 - W
; W = W - 1 ) { w [ c = 0 ] = I
[ 0 ] ; R ( e ( r , o ) , f ) (
m = W , i = 1 ; ! ( i > p [ 0 ]
. n ) ; i = i + 1 , m = m / 4 )
{ e ( f , i ) ( ( m & 3 ) < 2 )
{ e ( f , i ) ( m & 1 ) { w [ c
] . n e ( = , * ) I [ i ] . t ;
e ( f , i ) ( ( w [ c ] . t e (
= , * ) I [ i ] . n ) < 0 ) { w
[ c ] . n e ( = , * ) - 1 ; w [
c ] . t e ( = , * ) - 1 ; } } R
( e ( e , s ) , e ( l , e ) ) {
w [ c ] . n e ( = , * ) I [ i ]
. n ; w [ c ] . t e ( = , * ) I
[ i ] . t ; } } R ( e ( e , s )
, e ( l , e ) ) { w [ c = c + 1
] = I [ i ] ; } } R ( e ( r , o
) , f ) ( m = W , i = c = 0 ; i
< p [ 0 ] . n ; i = i + 1 , m =
m / 4 ) { e ( f , i ) ( ( m & 3
) > 1 ) { w [ 0 ] . n = w [ 0 ]
. n * w [ c + 1 ] . t + ( ( m &
1 ) ? - 1 : + 1 ) * w [ c + 1 ]
. n * w [ 0 ] . t ; w [ 0 ] . t
= w [ 0 ] . t * w [ c = c + 1 ]
. t ; } } n ( w ) ; e ( f , i )
( ! p [ 3 ] . t e ( | , | ) ( !
( p [ 3 ] . n - w [ 0 ] . n ) e
( & , & ) ! ( p [ 3 ] . t - w [
0 ] . t ) ) ) { R ( e ( r , o )
, f ) ( m = W , i = 0 ; i < p [
0 ] . n ; i = i + 1 , m = m / 4
) { o ( I [ i ] ) ; J = P C O (
% ) O ( c ) C , O ( * ) O ( / )
O ( + ) O ( - ) [ m & 3 ] ) ; }
o ( I [ i ] ) ; J = P C O ( = )
C ) ; o ( w [ 0 ] ) ; J = P O (
% ) O ( c ) , e ( 0 , 1 ) ) ; }
} H ( R ( e ( n , r ) , u ) , R
( e ( t , e ) , r ) ) J - 1 ; }
+129
View File
@@ -0,0 +1,129 @@
Best Algorithm:
Jens Schweikhardt
DFN Network Operation Center
Schlartaeckerweg 3 (home address)
D-71384 Weinstadt
Germany
http://www.uni-stuttgart.de/People/schweikhardt/home.html
Judges' comments:
To use:
make schweikh2
./schweikh2
Also try:
./schweikh2 15 1 0 0/0
The program accepts up to 4 parameters:
1) The number of operators in the expression [default: 9]
2) The value of the first operand [default: 1]
3) The (possibly negative) increment to the next operand [default: 1]
4) The goal value or 0/0 [default: 42]
The original program, with only slight obfuscations, may be found
in hunni.c. The perl script, obfuscates it appropriately:
perl ./hunni.pl < hunni.c
This entry was another crowd pleaser at the IOCCC BOF.
Selected notes from the author:
Note: the source must be viewed with tabstop 8. To appreciate the
beauty have your eyes half closed.
Why I think this program is obfuscated:
C is a free format language. It is therefore a question of style how
variables, operators, declarations, functions and syntactic elements
like braces and parentheses are grouped together. As a rule of thumb,
I put spaces around operators, after opening braces and before closing
braces. I have generalized this rule by putting whitespace after *any*
non-white space character (with the exception of preprocessor directives).
There are no recognizable keywords anymore. There are no recognizable
string literals any more. The main function is invisible. All operators
longer than one character have gone. They have been replaced by macro
calls with quite a number of arguments. The keys are the token pasting
and stringizing macros e and O. The "arcane rules of token pasting"
[K&R2] are used up to three levels, H(O,r)R(O,r)! which is needed to make
one 8-character token from 8 characters ('unsigned'). BTW, C has no 9 or
more character reserved words, so a fourth level is only required if
you intend to generate object names from 9 or more components. The final
round even swaps the tokens, so all keywords must be spelled backwards
(sort of, can you spot printf in the P macro?).
Try to indent the source. The unbalanced parentheses confuse Solaris'
indent to the max (although the result does compile):
Looking at the indented source is even *less* fun, because the nice
diamond pattern has been replaced by something that looks like, uhm,
modem noise.
Lint the source. It's clean. How obfuscated...
What's the exit status? The program exits with J - 1 where J is the
return value from several non-void functions (needed to shut up
lint). The last assignment is J = printf ("%c", 10); so the exit
status is 0 unless the last printf failed, which is even a *useful*
status. A further obfuscation is the use of 10 instead of '\n'.
'\n' can not be constructed by token pasting, AFAIK. That's why schweikh2
is likely to produce occasional garbage on non-ASCII execution character
set systems.
What this program does:
-----------------------
The program is an expression evaluator for a limited class of
expressions. Known operators are + - * /, operands are real numbers
(integers or fractions). The operands are restricted in that they must
differ by a constant value, for example 1 + 2 * 3 / 4 - 5. For any
combination of operators the expression is evaluated and compared to a
goal value. If they compare equal the expression is printed. If the goal
value is specified as 0/0 all expressions and results are printed. For
any fraction, the numerator and denominator are divided by their
greatest common divisor.
The program accepts up to 4 parameters:
1) The number of operators in the expression [default: 9]
2) The value of the first operand [1]
3) The (possibly negative) increment to the next operand [1]
4) The goal value or 0/0 [42]
On ANSI/ISO C conformant systems (where long is at least 32 bits)
overflow will occur in the default case (first operand 1, increment 1)
only for more than 11 operators. Because a bit mask is used that needs
twice the number of operands in bits (plus a sentinel value) on those
systems the first parameter must not exceed 15.
If long is at least 64 bits overflow will occur for more than 19
operators but you will probably wait quite some time for every of the
4^19 = 274,877,906,944 combinations to be evaluated... While I'm at it,
on a 50 MHz sparc, 4^11 expressions are evaluated in about 3 cpu
minutes (gcc -O3).
Sample arguments:
-----------------
$ schweikh2 6
$ schweikh2 7 0
$ schweikh2 7 7 0
$ schweikh2 8 9 -1 -67/21
$ schweikh2 8 2 2/5 -98/25
$ schweikh2 2 1/0 1 1/0
Miscellaneous
-------------
The diamond pattern can be continued without a break.
For a nice printout try this on your Bourne compatible shell
% while :; do grep -v '#' schweikh2.c; done