Found missing 1996/schweikh2 files
This commit is contained in:
1 parent
011112e1b2
commit
c69a99de37
3 files changed
+238
-7
No files matched your search
+130
@@ -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,
|
||||
¶m[i-1].num, ¶m[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
@@ -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";
|
||||
}
|
||||
@@ -35,13 +35,6 @@ Judges' comments:
|
||||
|
||||
perl ./hunni.pl < hunni.c
|
||||
|
||||
NOTE: No hunni.c nor hunni.pl is found in the IOCCC archives.
|
||||
Perhaps they were considered but never added to the entry?
|
||||
Perhaps someone somewhere has a copy of them? If so, then
|
||||
please send Email to the judges with info on how to find them:
|
||||
|
||||
http://www.ioccc.org/judges.html
|
||||
|
||||
This entry was another crowd pleaser at the IOCCC BOF.
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user