diff --git a/1989/fubar/README.md b/1989/fubar/README.md index 3442e0791..d9d1038a1 100644 --- a/1989/fubar/README.md +++ b/1989/fubar/README.md @@ -1,40 +1,47 @@ # Best self-modifying program - Jay Vosburgh - Sequent Computer Systems, Inc - 15450 SW Koll Parkway - Beaverton, OR - 97006 - USA +Jay Vosburgh +Sequent Computer Systems, Inc +15450 SW Koll Parkway +Beaverton, OR +97006 +USA ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) got this to work with modern systems. Thank you Cody for your assistance! -## To run +## To run: - ./fubar number> +```sh +./fubar +``` ## Try: - ./fubar 2 +```sh +./fubar 2 +``` -## Judges' remarks +## Judges' remarks: Run this with a single digit argument (or wait a long time). The blank line at the beginning of the source is mandatory. Do you know why? -NOTE: don't try running `ouroboros.c` directly with an arg as it'll turn into an -infinite loop. The same will happen with larger numbers. +NOTE: don't try running [ouroboros.c](ouroboros.c) (note that it's executable) +directly with an arg as it'll turn into an infinite loop. The same will happen +with larger numbers. -## Author's remarks +## Author's remarks: In a nutshell, this is probably the slowest and most obnoxious factorial program ever written. Unfortunately, @@ -46,7 +53,7 @@ The shell script compiles itself, and then executes the resulting binary, giving the source as input. The program works by successively modifying #define lines each pass through. -Both "indent" and "cb" will damage the program, "indent" +Both `indent` and `cb` will damage the program, `indent` much more so. ## Copyright and CC BY-SA 4.0 License: diff --git a/1989/jar.1/README.md b/1989/jar.1/README.md index 846005637..587d958ec 100644 --- a/1989/jar.1/README.md +++ b/1989/jar.1/README.md @@ -1,34 +1,40 @@ # Strangest abuse of the rules - Jari Arkko - Laboratory of Information Processing Science - Helsinki University of Technology - Otakaari 1 - 02150 Espoo - Finland +Jari Arkko +Laboratory of Information Processing Science +Helsinki University of Technology +Otakaari 1 +02150 Espoo +Finland ## To build and run: - make clobber all +```sh +make clobber all +``` -## Judges notes: +## Judges' remarks: On many systems the compiler will not allow you to send the object file to /dev/tty. The author suggested: - cc -c -o /dev/tty jar.1.c +```sh +cc -c -o /dev/tty jar.1.c +``` On systems that have symbolic links, we suggest: - ln -s /dev/tty jar.1.o - cc -c jar.1.c +```sh +ln -s /dev/tty jar.1.o +cc -c jar.1.c +``` As a last resort the scripts provided simply cat the .o file to the terminal. Abuse of the rules winners usually result in a change of the rules. Starting in 1990, compiling entries must result an regular file which can be executed. -## Selected notes from the author: +## Author's remarks: This program is (supposedly) the smallest C program able to print "Hello world.". The compilation itself produces the desired printout and the program diff --git a/1989/jar.2/README.md b/1989/jar.2/README.md index a426ddf25..255b5acee 100644 --- a/1989/jar.2/README.md +++ b/1989/jar.2/README.md @@ -1,33 +1,41 @@ ## Best of show - Jari Arkko, Ora Lassila, Esko Nuutila - Laboratory of Information Processing Science - Helsinki University of Technology - Otakaari 1 - 02150 Espoo - Finland +Jari Arkko, Ora Lassila, Esko Nuutila +Laboratory of Information Processing Science +Helsinki University of Technology +Otakaari 1 +02150 Espoo +Finland ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work with modern compilers. Modern compilers do not allow code like: - #define D define - #define a include +```c +#define D define +#define a include - #D foo bar - #a +#D foo bar +#a +``` + +He notes that there _is_ a way to get it (or something close to it) to work. Do +you know how? Thank you Cody for your assistance! ## To run: - - ./jar.2 - [enter some lisp] +```sh +./jar.2 +[enter some lisp] +``` NOTE: this entry will likely segfault on invalid input. @@ -40,15 +48,27 @@ all this functionality in such a small, densely packed program, is impressive enough to win the Best of show award. -## Selected notes from the author: +## Author's remarks: This program implements a Lisp interpreter in 1465 bytes of source. Some sophisticated features supported, eg. functionals and recursion. The special-forms/functions/variables implemented are: - + - * < () - car cdr cons defun equal - function if lambda quote t +- \+ +- \- +- \* +- \< +- () +- car +- cdr +- cons +- defun +- equal +- function +- if +- lambda +- quote +- t Below are sample lisp expressions you might choose to try as input. The program implements a conventional lisp listener, i.e. you type in @@ -56,6 +76,7 @@ lisp expressions (followed by CR), the program evaluates them and prints out the return values. End execution by typing an end-of-file character. +```lisp (+ 2.5 3.1) (defun fib (n) (if (< n 2) @@ -74,6 +95,7 @@ character. (cons (quote (f)) ()) (car (quote (a b c))) (cdr (cdr (quote (g h i)))) +``` Please do not leave any whitespace before the first parenthesis when diff --git a/1989/paul/README.md b/1989/paul/README.md index 97e00a9ef..a837936f3 100644 --- a/1989/paul/README.md +++ b/1989/paul/README.md @@ -1,20 +1,24 @@ ## Most complex algorithm - Paul E. Black - CIRRUS LOGIC, Inc. - 1463 Centre Pointe Dr. - Milpitas, CA - 95035 - USA +Paul E. Black +CIRRUS LOGIC, Inc. +1463 Centre Pointe Dr. +Milpitas, CA +95035 +USA ## To build: - make all +```sh +make all +``` ## Try: - ./paul +```sh +./paul +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault under macOS. The problem was that the int (from `#define f`) should be a long. This @@ -31,9 +35,9 @@ removing the trailing "\" on line 12 and joining lines 12 and WHAT FOLLOWS IS A DETAILED PROGRAM EXPLANATION AND SPOILER. IF YOU WANT A REAL CHALLENGE, DON'T READ ANY FURTHER AND TRY TO UNDERSTAND THE PROGRAM VIA THE SOURCE. - -Selected notes from the author: + +## Author's remarks: This programs computes and prints Fibonacci numbers by simulating a Turing machine with the proper program. @@ -78,8 +82,8 @@ If bit 4 (16&byte) is true, the next character is sent to stdout. (I added this feature so programs could print results.) -The Turing machine has next state 'j' when it begins. The -cycle is 1) exit if the state is 'x', 2) find the next +The Turing machine has next state `j` when it begins. The +cycle is 1) exit if the state is `x`, 2) find the next instruction (given the state and the character under the scan head). [The program string is searched forward for the next matching instruction. If the end of the string is reached, the diff --git a/1989/robison/README.md b/1989/robison/README.md index 326de2fec..06a7411dd 100644 --- a/1989/robison/README.md +++ b/1989/robison/README.md @@ -1,15 +1,17 @@ ## Best minimal use of C - Arch D. Robison - University of Illinois - 1304 W. Springfield Ave. - Urbana, IL - 61801 - USA +Arch D. Robison +University of Illinois +1304 W. Springfield Ave. +Urbana, IL +61801 +USA ## To build: - make all +```sh +make all +``` NOTE: we were able to get this to compile under modern systems with a patch from @@ -18,24 +20,27 @@ Yusuke! ## To run: - ./robison - # enter valid expressions - +```sh +./robison +# enter valid expressions +``` ## Try: - ./robison - 11x10 +```sh +./robison +11x10 - echo 1x10x111 | ./robison +echo 1x10x111 | ./robison - echo 1+1+10 | ./robison +echo 1+1+10 | ./robison - echo 100 - 1 | ./robison +echo 100 - 1 | ./robison - echo -100 x 100 + 1 | ./robison +echo -100 x 100 + 1 | ./robison - echo 100 / 100 | ./robison # <-- what happens here ? +echo 100 / 100 | ./robison # <-- what happens here ? +``` NOTE: this entry will crash with numbers with non binary digits. @@ -50,7 +55,7 @@ constructs that the C language supports. NOTE: this entry will likely dump core with invalid input. -## Selected notes from the author: +## Author's remarks: This program is a handy picoAPL interpreter written in C--. It outputs the evaluation of an APL expression from standard @@ -58,13 +63,17 @@ input. Functions are limited to dyadic +,-,x, and unary -; numerals must be binary. Parentheses may be used for grouping. For example: - 101x111-100 +``` +101x111-100 +``` prints: - 1111 +``` +1111 +``` -That is 5x(7-4) is 15. (APL groups from right to left.) +That is `5x(7-4)` is `15`. (APL groups from right to left.) Extending it to the full APL language should be trivial. The C-- language improves the C language by removing superfluous diff --git a/1989/roemer/README.md b/1989/roemer/README.md index eab87d6a1..912bf11a3 100644 --- a/1989/roemer/README.md +++ b/1989/roemer/README.md @@ -1,34 +1,37 @@ ## Best layout - Lievaart, Roemer B. - VU-Informatica, Amsterdam - Marcusstraat 29/2, - NL 1091 TJ Amsterdam - Netherlands +Lievaart, Roemer B. +VU-Informatica, Amsterdam +Marcusstraat 29/2, +NL 1091 TJ Amsterdam +Netherlands ## To build: - make all +```sh +make all +``` ## Try: - ./roemer +```sh +./roemer +``` ## Judges' remarks: Do you know what this program does? If you do, look again, there is more here than meets the PI. -## Selected notes from the author: +## Author's remarks: Passes lint, but not with the strictest options, for it contains some "null-statements", as well two identifiers which are, if compilers only take 6 characters, the same. It also uses write(2), so not totally system independent. -You are very much invited to pass this program through a -C-beautifier. (First strip newlines and tabs, if your cb can't -do that.) +You are very much invited to pass this program through a C-beautifier. (First +strip newlines and tabs, if your `cb` can't do that.) ## Copyright and CC BY-SA 4.0 License: diff --git a/1989/tromp/README.md b/1989/tromp/README.md index 4f62f86e3..9e0a30474 100644 --- a/1989/tromp/README.md +++ b/1989/tromp/README.md @@ -1,15 +1,16 @@ # Best game - John Tromp - Centre for Mathematics and Computer Science (CWI) - Oetgensstraat 7 - 1701CK Heerhugowaard - Netherlands +John Tromp +Centre for Mathematics and Computer Science (CWI) +Oetgensstraat 7 +1701CK Heerhugowaard +Netherlands ## To build: - make all - +```sh +make all +``` We used a patch from [Yusuke Endoh](/winners.html#Yusuke_Endoh) to get this to compile under gcc. Thank you Yusuke for your assistance! @@ -24,6 +25,40 @@ being created) and after this making sure the terminal stayed sane (the letter high score file was reinstated). We thank you for your assistance Cody (he cynically notes that he did it because tetris just has to work)! +## To run: + +```sh +./tromp [drops_per_sec [cmd_string]] +``` + +## Try: + +```sh +./tromp 5 + +# fast with vim keys +# h - left (left) +# k - rotate (arbitrary, in vim k = up) +# l - right (right) +# j - drop (down) +# space - pause (literal space in vim) +# q - quit (similar to :q in vim) + +./tromp 10 "hklj q" +``` + +NOTE: after this game ends a file called `HI` will be in the directory with the +high scores (up to 20 runs saved) so one can see who has the highest score. The +file might look like: + +``` +330 by cody +136 by cody +``` + +.... hey, I haven't played in a very long time and the lower one was hitting +space (default drop) in rapid succession :-) + ### Alternate code: @@ -32,39 +67,14 @@ were unable to see the improvements in modern systems even after fixing it to compile (the high score file was not created at all) but if you have an old compiler you can try compiling it in its original unmodified form by running: - make alt +```sh +make alt +``` + +Use `tromp.alt` as you would `tromp` above. -## To run: - - ./tromp [drops_per_sec [cmd_string]] - -## Try: - - ./tromp 5 - - # fast with vim keys - # h - left (left) - # k - rotate (arbitrary, in vim k = up) - # l - right (right) - # j - drop (down) - # space - pause (literal space in vim) - # q - quit (similar to :q in vim) - ./tromp 10 "hklj q" - -NOTE: after this game ends a file called `HI` will be in the directory with the -high scores (up to 20 runs saved) so one can see who has the highest score. The -file might look like: - - - 330 by cody - 136 by cody - - -.... hey, I haven't played in a very long time and the lower one was hitting -space (default drop) in rapid succession :-) - -## Judges' remarks +## Judges' remarks: This is a character terminal version of the TETRIS program. It runs on a VT100 compatible terminal or emulator. It is @@ -75,23 +85,23 @@ will drop in a second, is 2. The default "cmd_string" is "jkl pq". The first 6 characters of "cmd_string" relate to the following 6 game commands: - j - left - k - rotate - l - right - - drop - p - pause - q - quit +- j - left +- k - rotate +- l - right +- space - drop +- p - pause +- q - quit Specifying "cmd_string" allows one to re-define the commands. The pause command pauses the game, clears the screen and -prints the current score. To un-pause, type the pause +prints the current score. To resume, type the pause character again, which by default is "p". As was stated last year, we are likely to be more strict about portability in the future. [ We mean it this time :-) ] -## Author's remarks +## Author's remarks: This program plays the familiar game of `TETRIS' with the following features: @@ -131,6 +141,7 @@ at the start and -raw at the end. This further reduces the size of the program, but has the possible disadvantage that the program can only by stopped by 'q' or by the `kill -9' command. +```c long h[4];t(){h[3]-=h[3]/3000;setitimer(0,h,0);}c,d,l,v[]={(int)t,0,2},w,s,I,K =0,i=276,j,k,q[276],Q[276],*n=q,*m,x=17,f[]={7,-13,-12,1,8,-11,-12,-1,9,-1,1, 12,3,-13,-12,-1,12,-1,11,1,15,-1,13,1,18,-1,1,2,0,-12,-1,11,1,-12,1,13,10,-12, @@ -150,6 +161,7 @@ can only by stopped by 'q' or by the `kill -9' command. 0);while(getchar()-a[4]);puts("\033[H\033[J\033[7m");sigsetmask(s);}}d=popen( "stty -cbreak echo stop \023;sort -mnr -o HI - HI;cat HI","w");fprintf(d, "%4d from level %1d by %s\n",w,l,getlogin());pclose(d);} +``` ## Copyright and CC BY-SA 4.0 License: diff --git a/1989/vanb/README.md b/1989/vanb/README.md index 114b70095..a8111f831 100644 --- a/1989/vanb/README.md +++ b/1989/vanb/README.md @@ -1,21 +1,25 @@ ## Best one liner - David Van Brackle - Department of Computer Science - University of Central Florida - Orlando, Florida - 32816 - USA +David Van Brackle +Department of Computer Science +University of Central Florida +Orlando, Florida +32816 +USA ## To build: - make all +```sh +make all +``` ## Try: - ./vanb the rug gary lent - ./vanb unix is better than os/2 +```sh +./vanb the rug gary lent +./vanb unix is better than os/2 +``` ## Judges' remarks: @@ -25,7 +29,7 @@ element on each line, followed by a line of ten dashes. -## Selected notes from the author: +## Author's remarks: The program has the following charming and possibly non-portable features: diff --git a/1989/westley/README.md b/1989/westley/README.md index 7d7323d5b..096137a44 100644 --- a/1989/westley/README.md +++ b/1989/westley/README.md @@ -1,23 +1,24 @@ # Most algorithms in one program - Merlyn LeRoy (Brian Westley) - Starfire Consulting - 1026 Blair Ave. - St. Paul, MN - 55104 - USA - - http://www.westley.org +Merlyn LeRoy (Brian Westley) +Starfire Consulting +1026 Blair Ave. +St. Paul, MN +55104 +USA + ## To build: - make all +```sh +make all +``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) was able to get this to partially work with clang; clang requires that the second, third and fourth args to main() be `char **`. Only `westley.c` and `ver0.c` (see below) will -compile with clang. It's possible to get ver1.c to compile too but this causes +compile with clang. It's possible to get `ver1.c` to compile too but this causes problems with generating the output of the remaining files so we have opted, at least for now, to not do that, as it does not have to output just source code. He notes that the original source code sometimes segfaults with `ver2` which @@ -28,31 +29,32 @@ Thank you Cody for your help! ## Try: - - ./westley < westley.c > ver0.c - ./westley 1 < westley.c > ver1.c - ./westley 1 2 < westley.c > ver2.c - ./westley 1 2 3 < westley.c > ver3.c +```sh +./westley < westley.c > ver0.c +./westley 1 < westley.c > ver1.c +./westley 1 2 < westley.c > ver2.c +./westley 1 2 3 < westley.c > ver3.c +``` Try compiling and running the 4 resulting programs. To compile try: - - make ver0 - make ver1 - make ver2 - make ver3 +```sh +make ver0 +make ver1 +make ver2 +make ver3 +``` - -## Judges notes: +## Judges' remarks: There is a secret way to get ONE of the versions to print out "Hello, world!\n". Can you find how to do it? -## Selected notes from the author: +## Author's remarks: This is a filter. If it is run with no arguments, it copies stdin to stdout. With one argument, it ROT13's stdin to @@ -63,42 +65,44 @@ Also requires two's complement (I think). The source code will run if ROT13'ed and/or reversed, using a different algorithm for each version (hereafter referred to as -ver0 (original), ver1 (ROT13), ver2 (reversed), and ver3 +`ver0` (original), `ver1` (ROT13), `ver2` (reversed), and `ver3` (ROT13 and reversed)). When compiling these versions, one needs to define 'trgpune' in the compile line (which the Makefile now has). Example: - cc -Dtrgpune=putchar ver3.c -o ver3 +```sh +cc -Dtrgpune=putchar ver3.c -o ver3 +``` -"trgpune" is the ROT13 of getchar(), so getchar() and putchar() +`trgpune` is the ROT13 of `getchar()`, so `getchar()` and `putchar()` are exchanged in the ROT13 counterpart. It is easy to see that -this is unavoidable. I must have a #define for a library +this is unavoidable. I must have a `#define` for a library function; otherwise I would have an unidentified extern for the ROT13 version. If I then define this function, it won't link in the library version for the ORIGINAL code, since my definition will supersede the library function. Hence, the -compiler option gives me putchar(), and allows me to use -getchar(). I pass a dummy argument to getchar() to eliminate +compiler option gives me `putchar()`, and allows me to use +`getchar()`. I pass a dummy argument to `getchar()` to eliminate "variable number of args" from lint (unless it checks against the library). Otherwise, all versions lint reasonably (main returns random value & constant in conditional context [when I check for ROT13 version] is all it complains about). -ver0 and ver1 use a range check and a calculation to do ROT13, -while ver2 and ver3 use table lookup. All versions contain -main() and it's ROT13 fn, znva(). ver0/ver1 [ver2/ver3] are +`ver0` and `ver1` use a range check and a calculation to do ROT13, +while `ver2` and `ver3` use table lookup. All versions contain +`main()` and it's ROT13 fn, `znva()`. `ver0`/`ver1` [`ver2`/`ver3`] are (of course) syntactically identical, since the syntax is in the non-alphabetic characters. However, since one program starts -at main() while it's ROT13 counterpart starts at znva(), znva() -calls main (znva() is also used for output). +at `main()` while it's ROT13 counterpart starts at `znva()`, `znva()` +calls main (`znva()` is also used for output). All versions use recursion to work. If the program is NOT reversing it's output, it prints out the (possibly ROT13'd) character before recursing, otherwise it prints it out afterward (or doesn't recurse at all when EOF is reached). -Since most of this code is identical, it is put into znva() and -called with a first parameter of 0 as a flag (as "main()", it's +Since most of this code is identical, it is put into `znva()` and +called with a first parameter of 0 as a flag (as `main()`, it's first argument (argc) must be at least one). I can't use any flow control. If I used if(), I would have a @@ -106,45 +110,62 @@ function vs() to define in the ROT13 version. But a function called vs() turns into a function called if() in the original, so it can't be done. Therefore, I do: - expr1 && expr2 && (expr3=etc); +```c +expr1 && expr2 && (expr3=etc); +``` which is the same as: - if (expr1 && expr2) expr3=etc; +```c +if (expr1 && expr2) expr3=etc; +``` A/UX on the Macintosh doesn't get this right; it evaluates ALL expressions if they aren't in an assignment or conditional statement. This might warrant a warning, since other compilers may do this. I found MANY compilers botched: - expr1 && (expr2,expr3); +```c +expr1 && (expr2,expr3); +``` -expr2 was OFTEN evaluated even if expr1 was false. I removed +`expr2` was OFTEN evaluated even if `expr1` was false. I removed such statements to make it more portable. The variable names are worth noting: - 'irk' and 'vex' are ROT13 pairs and are synonyms. - 'Near' and 'Arne' are ROT13 pairs and are anagrams. - 'NOON' and 'ABBA' are ROT13 pairs and are palindromes. - 'tang' and 'gnat' are both ROT13 and palindrome pairs! +-- + +'irk' and 'vex' are ROT13 pairs and are synonyms. + +'Near' and 'Arne' are ROT13 pairs and are anagrams. + +'NOON' and 'ABBA' are ROT13 pairs and are palindromes. + +'tang' and 'gnat' are both ROT13 and palindrome pairs! + +-- Normally (!), a reversible C program is done thus: - /**/ forward code /*/ edoc drawkcab /**/ +```c +/**/ forward code /*/ edoc drawkcab /**/ +``` If your compiler nests comments, it will get this wrong. However, I have made some bits of the code palindromic, (or different, but reversible) so it is more like: - /**/forward/*//**/ palindromic /**//*/drawkcab/**/ +```c +/**/forward/*//**/ palindromic /**//*/drawkcab/**/ +``` The code can therefore be interlaced. There are eight such palindromic bits. You can find them within the `/*//**/ /**//*/` pairs. -The body of the code of ver0 and ver1 is a large lumpy 'K' (for -Kernighan); the code of ver2 and ver3 is a flat-topped and +The body of the code of `ver0` and `ver1` is a large lumpy 'K' (for +Kernighan); the code of `ver2` and `ver3` is a flat-topped and lumpier 'R' (for Ritchie). Judicious use of spaces and tabs helped here. It barely fits on an 80x24 screen. Squint. Note that the code must start with a blank line, or the reversed version