Here is the Tournament of Champions winner ... compiles without error using the SPARC C compiler - the first entry to get things down to THREE lines!!!


from Andre' Wilhelmus at wilhelmus@lucent.com
b;e;m;r;u;main(s,v)int*v;{for(v=fopen(v[1],"r");u=~fscanf(v,"%d",&s);m=!printf(
"%d %d\n",e-r,e))for(s*=s<987532;u--&7;m=--m*10)for(b=4;b+=b;b&u?n(u^=b,9),n(4,
r^=e=r),u^=b*=e-r< s:0)r=m++;}n(c,d){for(;c&7;d+=c>>13|1)u>>d&8?r=r*10+d,--c:0;}
(note - space added on last line so that HTML would show entire line)

The annotated version follows

/* POTM ENTRY:  alphabet_soup
   Your Name:   Andre' Wilhelmus
   Your email:  wilhelmus@lucent.com

   Version:     9c (961130)

   Begin with stop miles at 000000 and increment the digits from
   left to right while adding remaining unused digits high to low to the stop
   mile and low to high to the reset mile until a valid stop mile is reached.
 */

		/* #include  is missing. */
		/* The global declarations should be static int. */
miles;		/* Six digit mile counter while driving. 
		   A global non-static variable is set to zero as default .*/
reset;		/* Four digit resettable mile counter. */
start;		/* Start mileage. */
stop;		/* Six digit stop mile counter. */
unused;		/* Bit 12-3: unused digits 9-0.
		   Bit  2-0: number of digits left to complete the six digit
		   stop mile counter. */

		/* The keyword int is missing. */
main(digit,	/* Bit 12-3: digit number 9-0. */
     file)	/* Argument vector and FILE pointer.
		   The declaration of digit is missing. */
int *file;	/* Not portable: an int* is not a char**. */
{
  for (file = fopen(file[1], "r");	/* Open the input file.  Not portable:
					   an int* is not a FILE* and
					   an int is not a char*. */
       unused = ~fscanf(file, "%d",	/* Set all digits to unused and set
					   the number of digits left to six.
					   Lint expects == instead of =. */
			&start);	/* Read start mileage.  Not portable:
					   it assumes that EOF is -1 and that
					   the system has one zero. */

       /* Print the mileage where the reset button was pressed and the
	   stop mileage where all digits in both counters are unique. */

       miles = !printf("%d %d\n",	/* Print the result and clear miles. */
	         stop - reset, stop))
    for (start *= start < 987532;       /* Start at zero? */
	 unused-- & 7;		    	/* Decrement number of digits left.
				    	   Stop mileage complete? */
	 miles = --miles * 10)		/* Add digit position. */
      for (digit = 4;			/* Begin with digit 0. */
           digit += digit;		/* Next digit? */
           digit & unused ?		/* Digit unused? */
	     add_digits(unused^=digit, 9),	 /* Mark digit as used.
						    Calculate stop miles. */
             add_digits(4, reset^=stop=reset),   /* Save stop miles.  Clear and
						    calculate reset miles. */
	     unused |= digit *= stop-reset 0: increment digit.
				   < 0: decrement digit. */
	   dig_it)		/* Digit for mile counter.
				   The declarations of length, and dig_it
				   are missing. */
{
  for (;
       length & 7;		/* Number not complete? */
       dig_it += length>>13|1)	/* Next digit.  Not portable: it assumes that
				   the system has one zero and that the shift
				   right is arithmetic. */
    unused >> dig_it & 8 ?	/* Digit unused? */
      reset = reset*10+dig_it,	/* Add digit to number. */
      --length			/* Decrement length of number. */
    : 0;			/* Statement has null effect.
				   The return statement is missing.  The
				   result is stored in the variable reset. */
}












Make your own free website on Tripod.com