programming puzzle (silly)

Kjell Post kjell at saturn.ucsc.edu
Fri Mar 10 23:38:39 AEST 1989


In article <28336 at ucbvax.BERKELEY.EDU> klier at ucbarpa.Berkeley.EDU (Pete Klier) writes:
>
>***********************
>main(m,n){scanf("%d",&n);for(m=n>0^n>9;n&&m*=n--;);
>printf(m?"Answer=%d\n":"error\n",m);}
>***********************
>

But you changed the output.
I also get an error compiling this on an ISI68K.

As someone pointed out, my earlier solution breaks when arguments
are supplied at the command line.  I therefore propose the following
as the shortest version:

main(n,m){for(n=scanf("%d\n",&m);m>1&m<10;n*=m--);
printf(m-1?"error\n":"answer is %d\n",n);}

When written on a single line it should count to 91 characters.
I would also like to add the rule that the program should compile
without warnings from cc and lint (except for "scanf returns value
which is always ignored" which is always ignored).
-- 
      For athletes and programmers,  ! Kjell E. Post
a woman is the end of their career.  ! CIS/CE
                                     ! University of California, Santa Cruz
              -- A.Wickberg          ! Email: kjell at saturn.ucsc.edu



More information about the Comp.lang.c mailing list