Update 1989 winning entries' README.md files

Format and typo fixes.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-14 06:20:49 -07:00
1 parent 15787fbdd3
commit f458d5aefe
9 files changed
+281 -193

No files matched your search

+22 -15
View File
@@ -1,40 +1,47 @@
# Best self-modifying program # Best self-modifying program
Jay Vosburgh Jay Vosburgh
Sequent Computer Systems, Inc Sequent Computer Systems, Inc
15450 SW Koll Parkway 15450 SW Koll Parkway
Beaverton, OR Beaverton, OR
97006 97006
USA USA
## To build: ## To build:
make all ```sh
make all
```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) got this to work with [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) got this to work with
modern systems. Thank you Cody for your assistance! modern systems. Thank you Cody for your assistance!
## To run ## To run:
./fubar number> ```sh
./fubar <number>
```
## Try: ## Try:
./fubar 2 ```sh
./fubar 2
```
## Judges' remarks ## Judges' remarks:
Run this with a single digit argument (or wait a long time). Run this with a single digit argument (or wait a long time).
The blank line at the beginning of the source is mandatory. The blank line at the beginning of the source is mandatory.
Do you know why? Do you know why?
NOTE: don't try running `ouroboros.c` directly with an arg as it'll turn into an NOTE: don't try running [ouroboros.c](ouroboros.c) (note that it's executable)
infinite loop. The same will happen with larger numbers. 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 In a nutshell, this is probably the slowest and most
obnoxious factorial program ever written. Unfortunately, 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 resulting binary, giving the source as input. The program
works by successively modifying #define lines each pass through. 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. much more so.
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License:
+18 -12
View File
@@ -1,34 +1,40 @@
# Strangest abuse of the rules # Strangest abuse of the rules
Jari Arkko Jari Arkko
Laboratory of Information Processing Science Laboratory of Information Processing Science
Helsinki University of Technology Helsinki University of Technology
Otakaari 1 Otakaari 1
02150 Espoo 02150 Espoo
Finland Finland
## To build and run: ## 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 On many systems the compiler will not allow you to send the object file to
/dev/tty. The author suggested: /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: On systems that have symbolic links, we suggest:
ln -s /dev/tty jar.1.o ```sh
cc -c jar.1.c 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. 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 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. 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 This program is (supposedly) the smallest C program able to print "Hello
world.". The compilation itself produces the desired printout and the program world.". The compilation itself produces the desired printout and the program
+40 -18
View File
@@ -1,33 +1,41 @@
## Best of show ## Best of show
Jari Arkko, Ora Lassila, Esko Nuutila Jari Arkko, Ora Lassila, Esko Nuutila
Laboratory of Information Processing Science Laboratory of Information Processing Science
Helsinki University of Technology Helsinki University of Technology
Otakaari 1 Otakaari 1
02150 Espoo 02150 Espoo
Finland Finland
## To build: ## To build:
make all ```sh
make all
```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work with [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work with
modern compilers. Modern compilers do not allow code like: modern compilers. Modern compilers do not allow code like:
#define D define ```c
#define a include #define D define
#define a include
#D foo bar #D foo bar
#a <stdio.h> #a <stdio.h>
```
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! Thank you Cody for your assistance!
## To run: ## To run:
```sh
./jar.2 ./jar.2
[enter some lisp] [enter some lisp]
```
NOTE: this entry will likely segfault on invalid input. 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. 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. This program implements a Lisp interpreter in 1465 bytes of source.
Some sophisticated features supported, eg. functionals and recursion. Some sophisticated features supported, eg. functionals and recursion.
The special-forms/functions/variables implemented are: 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. Below are sample lisp expressions you might choose to try as input.
The program implements a conventional lisp listener, i.e. you type in 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 prints out the return values. End execution by typing an end-of-file
character. character.
```lisp
(+ 2.5 3.1) (+ 2.5 3.1)
(defun fib (n) (defun fib (n)
(if (< n 2) (if (< n 2)
@@ -74,6 +95,7 @@ character.
(cons (quote (f)) ()) (cons (quote (f)) ())
(car (quote (a b c))) (car (quote (a b c)))
(cdr (cdr (quote (g h i)))) (cdr (cdr (quote (g h i))))
```
Please do not leave any whitespace before the first parenthesis when Please do not leave any whitespace before the first parenthesis when
+16 -12
View File
@@ -1,20 +1,24 @@
## Most complex algorithm ## Most complex algorithm
Paul E. Black Paul E. Black
CIRRUS LOGIC, Inc. CIRRUS LOGIC, Inc.
1463 Centre Pointe Dr. 1463 Centre Pointe Dr.
Milpitas, CA Milpitas, CA
95035 95035
USA USA
## To build: ## To build:
make all ```sh
make all
```
## Try: ## Try:
./paul ```sh
./paul
```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault under [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 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. WHAT FOLLOWS IS A DETAILED PROGRAM EXPLANATION AND SPOILER.
IF YOU WANT A REAL CHALLENGE, DON'T READ ANY FURTHER AND TRY IF YOU WANT A REAL CHALLENGE, DON'T READ ANY FURTHER AND TRY
TO UNDERSTAND THE PROGRAM VIA THE SOURCE. TO UNDERSTAND THE PROGRAM VIA THE SOURCE.
Selected notes from the author:
## Author's remarks:
This programs computes and prints Fibonacci numbers by This programs computes and prints Fibonacci numbers by
simulating a Turing machine with the proper program. 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 stdout. (I added this feature so programs could print
results.) results.)
The Turing machine has next state 'j' when it begins. The The Turing machine has next state `j` when it begins. The
cycle is 1) exit if the state is 'x', 2) find the next cycle is 1) exit if the state is `x`, 2) find the next
instruction (given the state and the character under the scan instruction (given the state and the character under the scan
head). [The program string is searched forward for the next head). [The program string is searched forward for the next
matching instruction. If the end of the string is reached, the matching instruction. If the end of the string is reached, the
+30 -21
View File
@@ -1,15 +1,17 @@
## Best minimal use of C ## Best minimal use of C
Arch D. Robison Arch D. Robison
University of Illinois University of Illinois
1304 W. Springfield Ave. 1304 W. Springfield Ave.
Urbana, IL Urbana, IL
61801 61801
USA USA
## To build: ## To build:
make all ```sh
make all
```
NOTE: we were able to get this to compile under modern systems with a patch from NOTE: we were able to get this to compile under modern systems with a patch from
@@ -18,24 +20,27 @@ Yusuke!
## To run: ## To run:
./robison ```sh
# enter valid expressions ./robison
# enter valid expressions
```
## Try: ## Try:
./robison ```sh
11x10 ./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. 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. 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 This program is a handy picoAPL interpreter written in C--. It
outputs the evaluation of an APL expression from standard 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 numerals must be binary. Parentheses may be used for
grouping. For example: grouping. For example:
101x111-100 ```
101x111-100
```
prints: 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. Extending it to the full APL language should be trivial.
The C-- language improves the C language by removing superfluous The C-- language improves the C language by removing superfluous
+14 -11
View File
@@ -1,34 +1,37 @@
## Best layout ## Best layout
Lievaart, Roemer B. Lievaart, Roemer B.
VU-Informatica, Amsterdam VU-Informatica, Amsterdam
Marcusstraat 29/2, Marcusstraat 29/2,
NL 1091 TJ Amsterdam NL 1091 TJ Amsterdam
Netherlands Netherlands
## To build: ## To build:
make all ```sh
make all
```
## Try: ## Try:
./roemer ```sh
./roemer
```
## Judges' remarks: ## Judges' remarks:
Do you know what this program does? If you do, look again, Do you know what this program does? If you do, look again,
there is more here than meets the PI. 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 Passes lint, but not with the strictest options, for it
contains some "null-statements", as well two identifiers contains some "null-statements", as well two identifiers
which are, if compilers only take 6 characters, the same. It which are, if compilers only take 6 characters, the same. It
also uses write(2), so not totally system independent. also uses write(2), so not totally system independent.
You are very much invited to pass this program through a You are very much invited to pass this program through a C-beautifier. (First
C-beautifier. (First strip newlines and tabs, if your cb can't strip newlines and tabs, if your `cb` can't do that.)
do that.)
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License:
+58 -46
View File
@@ -1,15 +1,16 @@
# Best game # Best game
John Tromp John Tromp
Centre for Mathematics and Computer Science (CWI) Centre for Mathematics and Computer Science (CWI)
Oetgensstraat 7 Oetgensstraat 7
1701CK Heerhugowaard 1701CK Heerhugowaard
Netherlands Netherlands
## To build: ## To build:
make all ```sh
make all
```
We used a patch from [Yusuke Endoh](/winners.html#Yusuke_Endoh) We used a patch from [Yusuke Endoh](/winners.html#Yusuke_Endoh)
to get this to compile under gcc. Thank you Yusuke for your assistance! 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 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)! 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: ### 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 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: 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: ## Judges' remarks:
./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
This is a character terminal version of the TETRIS program. This is a character terminal version of the TETRIS program.
It runs on a VT100 compatible terminal or emulator. It is 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 "jkl pq". The first 6 characters of "cmd_string" relate
to the following 6 game commands: to the following 6 game commands:
j - left - j - left
k - rotate - k - rotate
l - right - l - right
<space> - drop - space - drop
p - pause - p - pause
q - quit - q - quit
Specifying "cmd_string" allows one to re-define the commands. Specifying "cmd_string" allows one to re-define the commands.
The pause command pauses the game, clears the screen and 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". character again, which by default is "p".
As was stated last year, we are likely to be more strict about As was stated last year, we are likely to be more strict about
portability in the future. [ We mean it this time :-) ] 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 This program plays the familiar game of `TETRIS' with the
following features: 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 the program, but has the possible disadvantage that the program
can only by stopped by 'q' or by the `kill -9' command. 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 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, =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, 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( 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, "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);} "%4d from level %1d by %s\n",w,l,getlogin());pclose(d);}
```
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License:
+14 -10
View File
@@ -1,21 +1,25 @@
## Best one liner ## Best one liner
David Van Brackle David Van Brackle
Department of Computer Science Department of Computer Science
University of Central Florida University of Central Florida
Orlando, Florida Orlando, Florida
32816 32816
USA USA
## To build: ## To build:
make all ```sh
make all
```
## Try: ## Try:
./vanb the rug gary lent ```sh
./vanb unix is better than os/2 ./vanb the rug gary lent
./vanb unix is better than os/2
```
## Judges' remarks: ## 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 The program has the following charming and possibly
non-portable features: non-portable features:
+69 -48
View File
@@ -1,23 +1,24 @@
# Most algorithms in one program # Most algorithms in one program
Merlyn LeRoy (Brian Westley) Merlyn LeRoy (Brian Westley)
Starfire Consulting Starfire Consulting
1026 Blair Ave. 1026 Blair Ave.
St. Paul, MN St. Paul, MN
55104 55104
USA USA
<http://www.westley.org>
http://www.westley.org
## To build: ## To build:
make all ```sh
make all
```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) was able to get [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 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 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 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. 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 He notes that the original source code sometimes segfaults with `ver2` which
@@ -28,31 +29,32 @@ Thank you Cody for your help!
## Try: ## Try:
```sh
./westley < westley.c > ver0.c ./westley < westley.c > ver0.c
./westley 1 < westley.c > ver1.c ./westley 1 < westley.c > ver1.c
./westley 1 2 < westley.c > ver2.c ./westley 1 2 < westley.c > ver2.c
./westley 1 2 3 < westley.c > ver3.c ./westley 1 2 3 < westley.c > ver3.c
```
Try compiling and running the 4 resulting programs. To compile try: Try compiling and running the 4 resulting programs. To compile try:
```sh
make ver0 make ver0
make ver1 make ver1
make ver2 make ver2
make ver3 make ver3
```
## Judges' remarks:
## Judges notes:
There is a secret way to get ONE of the versions to print out There is a secret way to get ONE of the versions to print out
"Hello, world!\n". Can you find how to do it? "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 This is a filter. If it is run with no arguments, it copies
stdin to stdout. With one argument, it ROT13's stdin to 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 The source code will run if ROT13'ed and/or reversed, using a
different algorithm for each version (hereafter referred to as 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)). (ROT13 and reversed)).
When compiling these versions, one needs to define 'trgpune' When compiling these versions, one needs to define 'trgpune'
in the compile line (which the Makefile now has). Example: 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 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 function; otherwise I would have an unidentified extern for the
ROT13 version. If I then define this function, it won't link ROT13 version. If I then define this function, it won't link
in the library version for the ORIGINAL code, since my in the library version for the ORIGINAL code, since my
definition will supersede the library function. Hence, the definition will supersede the library function. Hence, the
compiler option gives me putchar(), and allows me to use compiler option gives me `putchar()`, and allows me to use
getchar(). I pass a dummy argument to getchar() to eliminate `getchar()`. I pass a dummy argument to `getchar()` to eliminate
"variable number of args" from lint (unless it checks against "variable number of args" from lint (unless it checks against
the library). Otherwise, all versions lint reasonably (main the library). Otherwise, all versions lint reasonably (main
returns random value & constant in conditional context [when I returns random value & constant in conditional context [when I
check for ROT13 version] is all it complains about). check for ROT13 version] is all it complains about).
ver0 and ver1 use a range check and a calculation to do ROT13, `ver0` and `ver1` use a range check and a calculation to do ROT13,
while ver2 and ver3 use table lookup. All versions contain while `ver2` and `ver3` use table lookup. All versions contain
main() and it's ROT13 fn, znva(). ver0/ver1 [ver2/ver3] are `main()` and it's ROT13 fn, `znva()`. `ver0`/`ver1` [`ver2`/`ver3`] are
(of course) syntactically identical, since the syntax is in the (of course) syntactically identical, since the syntax is in the
non-alphabetic characters. However, since one program starts non-alphabetic characters. However, since one program starts
at main() while it's ROT13 counterpart starts at znva(), znva() at `main()` while it's ROT13 counterpart starts at `znva()`, `znva()`
calls main (znva() is also used for output). calls main (`znva()` is also used for output).
All versions use recursion to work. If the program is NOT All versions use recursion to work. If the program is NOT
reversing it's output, it prints out the (possibly ROT13'd) reversing it's output, it prints out the (possibly ROT13'd)
character before recursing, otherwise it prints it out character before recursing, otherwise it prints it out
afterward (or doesn't recurse at all when EOF is reached). afterward (or doesn't recurse at all when EOF is reached).
Since most of this code is identical, it is put into znva() and 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 called with a first parameter of 0 as a flag (as `main()`, it's
first argument (argc) must be at least one). first argument (argc) must be at least one).
I can't use any flow control. If I used if(), I would have a 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, called vs() turns into a function called if() in the original,
so it can't be done. Therefore, I do: so it can't be done. Therefore, I do:
expr1 && expr2 && (expr3=etc); ```c
expr1 && expr2 && (expr3=etc);
```
which is the same as: 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 A/UX on the Macintosh doesn't get this right; it evaluates ALL
expressions if they aren't in an assignment or conditional expressions if they aren't in an assignment or conditional
statement. This might warrant a warning, since other compilers statement. This might warrant a warning, since other compilers
may do this. I found MANY compilers botched: 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. such statements to make it more portable.
The variable names are worth noting: 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. 'irk' and 'vex' are ROT13 pairs and are synonyms.
'tang' and 'gnat' are both ROT13 and palindrome pairs!
'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: 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. If your compiler nests comments, it will get this wrong.
However, I have made some bits of the code palindromic, However, I have made some bits of the code palindromic,
(or different, but reversible) so it is more like: (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 The code can therefore be interlaced. There are eight
such palindromic bits. You can find them within the such palindromic bits. You can find them within the
`/*//**/ /**//*/` pairs. `/*//**/ /**//*/` pairs.
The body of the code of ver0 and ver1 is a large lumpy 'K' (for 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 Kernighan); the code of `ver2` and `ver3` is a flat-topped and
lumpier 'R' (for Ritchie). Judicious use of spaces and tabs lumpier 'R' (for Ritchie). Judicious use of spaces and tabs
helped here. It barely fits on an 80x24 screen. Squint. Note helped here. It barely fits on an 80x24 screen. Squint. Note
that the code must start with a blank line, or the reversed version that the code must start with a blank line, or the reversed version