Results of the 1. Int'l Kaiserslautern
Shortest C Contest (ShoCC)

We are terribly sorry that we needed so much time to get this posted.  Our apologies go to all the people who have waited patiently for this announcement.  (And also to those who were less patient.)

On February, 13th, 1995 the 1. Int'l Kaiserslautern Shortest C Contest (ShoCC) was announced.  Its subject was to write a C program that counts from a given number i1 upto or downto a second given number i2.  The program consisting of the fewest characters (including space and newline chars) was to win the contest.  For full details see the contest rules at

http://www.unix-ag.uni-kl.de/~conrad/shocc/shocc_en.html
Until the deadline of Wednesday, February, 23rd, 1995, 23:59:59 MET we received 375 submissions from 184 participants.  Six of the 375 entries did not compile on our testsuite and 45 had runtime errors during a test process.

Unfortunately most of the programs did not fulfil one of the specifications made in the announcement, but our automated check script did not discover this violation of the rules: Many programs computed a difference of i1 and i2, decremented or incremented it according to the sign of this difference and terminated their loop when this difference was zero.  As you can see the sign of this difference is important.  Unfortunately the difference of two signed integers does not in every case fit into a signed int: Obviously

   (MAXINT - -5) > MAXINT
and does not fit into a signed integer variable, but is interpreted as a negative number and will break the program.  This is especially true if the program is invoked with
 $ foo MAXINT MININT
We didn't include this case in our test scripts because of the long running time of this command.  Michael Bischoff <mbi@mo.math.nat.tu-bs.de> even asked if the program had to work correctly when the difference was greater than MAXINT.  We confirmed this, not overseeing the implications of this question.  We discovered this pathologic case only when the contest deadline was over.

Since we had already confirmed the successful testing of these programs we finally decided to declare submissions correct even if this overflow error occured.  We apologize to Michael that we have to contradict our former answer in this case.

With this in mind, there are 19 victorious submissions all with a length of 69 bytes of code (including a trailing newline):

In no particular order:

[01] main(a,y,d)int*y;{for(a=atoi(y[1]);o(a),d=atoi(y[2])-a;)a+=(d|1)%2;}
[02] main(c,v,x)int*v;{for(c=atoi(v[1]);o(c),x=atoi(v[2])-c;c+=(x|1)%2);}
[03] main(a,v)int*v;{for(a=atoi(*++v);o(a),*v=atoi(v[1])-a;a+=*v>>31|1);}
[04] main(i,v,j)int*v;{for(i=atoi(v[1]);o(i),j=atoi(v[2])-i;i+=(j|1)%2);}
[05] main(c,d){int*v=d;for(c=atoi(v[1]);o(c),d=atoi(v[2])-c;c+=d>>31|1);}
[06] main(d,O,_)int*O;{for(_=atoi(O[1]);o(_),d=_-atoi(O[2]);_-=d>>-1|1);}
[07] main(a,v)int*v;{for(a=atoi(v[1]);o(a),*v=atoi(v[2])-a;a+=*v>>31|1);}
[08] main(a,b)int*b;{for(a=atoi(*++b);o(a),*b=atoi(b[1])-a;a+=(*b|1)%2);}
[09] main(a,b)int*b;{for(a=atoi(b[1]);o(a),*b=atoi(b[2])-a;a+=*b>>31|1);}
[10] main(J,_)int*_;{for(J=atoi(*++_);o(J),*_=atoi(_[1])-J;J+=(*_|1)%2);}
[11] main(i,b,j)int*b;{for(i=atoi(b[1]);o(i),j=i-atoi(b[2]);i-=j>>31|1);}
[12] main(k,j,i)int*j;{for(k=atoi(j[1]);o(k),i=atoi(j[2])-k;k+=(i|1)%2);}
[13] main(n,a,e)int*a;{for(n=atoi(a[1]);o(n),e=atoi(a[2])-n;n+=e>>31|1);}
[14] a;main(c,d)int*d;{for(a=atoi(d[1]);o(a),c=atoi(d[2])-a;a+=(c|1)%2);}
[15] main(n,c,d)int*c;{for(n=atoi(c[1]);o(n),d=atoi(c[2])-n;n+=d>>31|1);}
[16] main(d,a)int*a;{for(d=atoi(a[1]);o(d),*a=atoi(a[2])-d;d+=(*a|1)%2);}
[17] *p;main(i,x){for(i=atoi((p=x)[1]);o(i),x=atoi(p[2])-i;x>0?i++:i--);}
[18] main(c,v,d)int*v;{for(c=atoi(v[1]);o(c),d=atoi(v[2])-c;c+=d>>31|1);}
[19] main(c,v,d)int*v;{for(c=atoi(v[1]);d;o(d>0?c++:c--))d=atoi(v[2])-c;}
These are the winners of the 1. Int'l Kaiserslautern Shortest C Contest (the numbers refer to the programs above):
[01] Lars C. Hassing <lch@cci.dk>
[02] Stefan Bock <sbock@informatik.uni-kl.de>
[03] Heather Downs <heathbar@natasha.tele.iastate.edu>
[04] Patrick Seemann <tele@tubul.limmat.net.ch>
[05] Roland Nagel <nagel@informatik.uni-kl.de>
[06] Klaus Singvogel <kssingvo@immd4.informatik.uni-erlangen.de>,
     Michael Schroeder <mlschroe@faui43.informatik.uni-erlangen.de>,
     Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
[07] Markus Simmer <simmer@iml.fhg.de>
[08] Willy Seibert <ws@osix.materna.de>
[09] Oliver Bianzano <oli@ap-pc818c.physik.uni-karlsruhe.de>
[10] Jens Schweikhardt <jenssch@ibhinfo.hemminger-gdv.de>
[11] Thomas Omerzu <omerzu@quantum.de>,
     Matthias Sachs <sachs@quantum.de>,
     Udo Salewski <salewski@quantum.de>
[12] Jahn Rentmeister <WIJARE@wi.uni-muenster.de>
[13] Gregor Hoffleit <flight@mathi.uni-heidelberg.de>
[14] John Rochester <jr@cs.mun.ca>
[15] Markus Siegert <siegertm@nemeter.dinoco.de>
[16] Siegmar Zaeske <zaeske@detlef.informatik.uni-dortmund.de>
[17] Arnd Gerns <gerns@informatik.uni-hildesheim.de>,
     Dirk Eiden <eiden@informatik.uni-hildesheim.de>,
     Steffen Moeller <moeller@informatik.uni-hildesheim.de>
[18] James C. Hu <jxh@pride.cs.wustl.edu>
[19] Frank Neblung <neblung@informatik.uni-kl.de>
Congratulations to the winners and all other contestants for the very inspiring submissions.  Here is the distribution of the TOP 15 ranks:
               RANK  # PROGRAMS  LENGTH
               --------------------------
                 1      19      69 Bytes
                 2      21      70 Bytes
                 3       6      71 Bytes
                 4      14      72 Bytes
                 5      15      73 Bytes
                 6      10      74 Bytes
                 7       3      75 Bytes
                 8       9      76 Bytes
                 9       5      77 Bytes
                10       6      78 Bytes
                11      10      79 Bytes
                12       7      80 Bytes
                13       4      82 Bytes
                14       6      83 Bytes
                15       1      84 Bytes
We hope we did not forget your submission.  If you mailed a submission to us but got no ack, mail us again and we'll try to figure out what happened.

Origin of the contestants

The participants came from at least 14 countries:
 274 de   Germany
  35 com  all over the world, mostly USA and Germany
  20 net  dito
  19 edu  mostly USA
  18 org  all over the world, mostly Germany and USA
   8 dk   Denmark
   7 uk   United Kingdom
   6 su   Former Sovjet Union, here: Usbekistan
   5 fr   France
   4 nl   Netherlands
   4 ch   Switzerland
   4 ca   Canada
   2 it   Italy
   2 gov  USA
   2 at   Austria
   2 se   Sweden
   1 sg   Singapore

Quick Analysis of All Entries

This analysis looks over 365 submissions to the ShoCC contest.  There may be more than one entry of one author/team.  All values are some kind of approximate as I grep'ed, sed'ed sort'ed and uniq'ed all submissions by hand.  I hope this gives a quick overview to the variety of submissions.

Total number of analyzed entries: 365

Type of looping

for                                     277
while                                   50
do                                      7
goto                                    6

other                                   16

Reading commandline parameters

atoi                                    99%
atol                                    1
scanf                                   5

*++v                                    57
v[1]                                    301
1[v]                                    8

Declaring functions, parameters and variables

int main()                              11
void main()                             7

main(int c, ...                         127
     ..., char **)                      90
     ..., int **)                       28

k&r char **v                            51
k&r int  **v                            47

k&r int   *v                            120
  used *v as int                        35
k&r long  *v                            1

no explicit type declaration            1

global int variables                    18
global *int variables                   1

additional functions (recursion):       4
declaration of o()                      2

Usage of the preprocessor

#include <stdio.h                       16
#include <stdlib.h>                     16

#define i=atoi(T[1]) and variants       12
other defines                           3

Analysis of the "for"-single-line entries:

Total                                   271

Definitions of positions: for (A; B; C) D;

A: called atoi() once                   120
   called atoi() twice                  67
   called o()                           65

B: o(a), b=atoi(v[2])-a construct       70
   no atoi(), a-b termination           99
   no atoi(), o(a)                      87

C: empty                                15
   a<b?a++:a-- variants                 92
   a<0?d++:d-- variants                 29
   l+=l<i?1:-1 variants                 69

Library functions used

atoi()                                  355
printf()                                40
abs()                                   13
scanf()                                 4
exit()                                  2
system()                                1
atol()                                  1

Other C-constructs used

if                                      39
else                                    13
return                                  13

C-operators

^                                       15
%2                                      14
>>                                      17
|1                                      32
?:                                      283
/, /=                                   8
+=                                      141
-=                                      22

Hitlist of variable names

 200 v     15 s         3 X
 193 a     12 z         2 g
 170 c     11 O         2 S
 161 b     10 p         2 L
 103 i      9 f         2 I
  92 d      9 argv      2 B
  80 j      9 argc      2 A
  39 n      8 l         1 nr
  36 x      6 t         1 arg
  32 y      5 J         1 T
  25 k      3 w         1 K
  24 h      3 r
  23 _      3 q
  17 e      3 m
Note that there are all lower case characters used except of 'u'!

Shortest known solution

Composing from all submissions there are now even shorter solutions available.  A nice one with only 66 characters comes from Heather Downs <relayer@netcom.com>:
    *v;main(a,b){for(a=atoi(1[v=b]);o(a),b=atoi(v[2])-a;a+=(b|1)%2);}

Most obfuscated solutions

We got many obfuscated submissions, but naming a variable '_' or writing 1[v] instead of v[1] was not enough.  Since it was quite hard to decide which one to select for "most obfuscated code" we decided to give this prize to the following people for their submissions:

1st price: Markus Freericks <mfx@cs.tu-berlin.de>

main(b,v,a)char**v;{b=atoi(v[2]);o(b+((a=atoi(v[1]))^b&&sprintf(*v,
"%s %d %d",*v,a,b+(b>a?-1:1))&&system(*v),0));}
2nd price: Hans-Christoph Wirth <hansi@dianoia.mayn.sub.de>
#define m(x,y)x=atoi(y[(int*)b]),
main(a,b,i){a-3?(o(i),(i-b)&&main(a,b,i+a)):(m(i,1)m(b,2)
main(i<b?1:-1,b,i));} 
3rd price: Arnd Gerns, Steffen Moeller, Dirk Eiden
*p;main(i,x){for(i=atoi((p=x)[1]);o(i),x=atoi(p[2])-i;x>0?i++:i--);}
4th price: Jens Gebhard <gebharj@goedel.uni-muenster.de>
main(c,v,i)int*v;{c-i?main(v?atoi(v[1]):c+2*(o(c),c<i)-1,0,
v?atoi(v[2]):i):o(c);}
Note that the line breaks at the obvious places were inserted by us for better readability in newsreaders only.

Web Server

This summary of the results will be mailed to all participants and will also be posted to the newsgroups where the announcement appeared.  For more details including more detailed statistics, ALL sent-in programs and more check out our web page at
URL: http://www.unix-ag.uni-kl.de/~conrad/shocc/shocc.html
We will also make a tar archive containing this information along with some more or less useful "AI"-scripts that helped us evaluate the submissions.

Your Feedback

Since this was the first contest we organized and since some aspects were not so well thought through (as no doubt some of you may have noticed :-), we'd appreciate some feedback from you with respect to the following questions: Thank you for your answers and submissions.  We had one and a half week of fun and extreme stress.  We hope you enjoyed the contest.  We did.
Signed,
The Contest Comittee of the 1. Int'l Kaiserslautern ShoCC

Nils Magnus                                 Peter Conrad

Disclaimer: And now kids, be nice and go back to your normal programming habits that you learned from Uncle Dijkstra and the SE courses ;-}


Markup March 1995 by jutta@pobox.com.