URL and format fix 1996/schweikh2/README.md

This commit is contained in:
Cody Boone Ferguson committed 2023-04-18 09:28:04 -07:00
1 parent 231ab04074
commit 2f04c16b00
1 file changed
+66 -46
+66 -46
View File
@@ -1,20 +1,24 @@
# Best Algorithm # Best Algorithm
Jens Schweikhardt Jens Schweikhardt
DFN Network Operation Center DFN Network Operation Center
Schlartaeckerweg 3 (home address) Schlartaeckerweg 3 (home address)
D-71384 Weinstadt D-71384 Weinstadt
Germany Germany
<http://www.schweikhardt.net>
http://www.uni-stuttgart.de/People/schweikhardt/home.html
## To build: ## To build:
make all ```sh
make all
```
## To run: ## To run:
./schweikh2 ```sh
./schweikh2
```
The program accepts up to 4 parameters: The program accepts up to 4 parameters:
@@ -29,11 +33,25 @@ The program accepts up to 4 parameters:
## Try: ## Try:
./schweikh2 15 1 0 0/0 ```sh
./schweikh2 15 1 0 0/0
```
What happens if you pass only three parameters like the below? What happens if you pass only three parameters like the below?
./schweikh2 15 1 0 ```sh
./schweikh2 15 1 0
```
The author also suggests:
```sh
while :; do grep -v '#' schweikh2.c; done
```
(and we do too) which works with `sh`, `bash`, `ksh` and `zsh` as well.
## Judges' remarks: ## Judges' remarks:
@@ -41,7 +59,9 @@ What happens if you pass only three parameters like the below?
The original program, with only slight obfuscations, may be found The original program, with only slight obfuscations, may be found
in `hunni.c`. The perl script, obfuscates it appropriately: in `hunni.c`. The perl script, obfuscates it appropriately:
perl ./hunni.pl < hunni.c ```sh
perl ./hunni.pl < hunni.c
```
This entry was another crowd pleaser at the IOCCC BOF. This entry was another crowd pleaser at the IOCCC BOF.
@@ -79,34 +99,33 @@ modem noise.
Lint the source. It's clean. How obfuscated... Lint the source. It's clean. How obfuscated...
What's the exit status? The program exits with J - 1 where J is the What's the exit status? The program exits with `J - 1` where `J` is the
return value from several non-void functions (needed to shut up return value from several non-void functions (needed to shut up
lint). The last assignment is J = printf ("%c", 10); so the exit lint). The last assignment is `J = printf ("%c", 10);` so the exit
status is 0 unless the last printf failed, which is even a *useful* status is 0 unless the last `printf` failed, which is even a *useful*
status. A further obfuscation is the use of 10 instead of '\n'. status. A further obfuscation is the use of `10` instead of `'\n'`.
'\n' can not be constructed by token pasting, AFAIK. That's why `schweikh2` `'\n'` can not be constructed by token pasting, AFAIK. That's why `schweikh2`
is likely to produce occasional garbage on non-ASCII execution character is likely to produce occasional garbage on non-ASCII execution character
set systems. set systems.
What this program does: ### What this program does
-----------------------
The program is an expression evaluator for a limited class of The program is an expression evaluator for a limited class of expressions. Known
expressions. Known operators are + - * /, operands are real numbers operators are `+` `-` `*` `/`; operands are real numbers (integers or
(integers or fractions). The operands are restricted in that they must fractions). The operands are restricted in that they must differ by a constant
differ by a constant value, for example 1 + 2 * 3 / 4 - 5. For any value, for example `1 + 2 * 3 / 4 - 5`. For any combination of operators the
combination of operators the expression is evaluated and compared to a expression is evaluated and compared to a goal value. If they compare equal the
goal value. If they compare equal the expression is printed. If the goal expression is printed. If the goal value is specified as `0/0` all expressions
value is specified as 0/0 all expressions and results are printed. For and results are printed. For any fraction, the numerator and denominator are
any fraction, the numerator and denominator are divided by their divided by their greatest common divisor.
greatest common divisor.
The program accepts up to 4 parameters: The program accepts up to 4 parameters:
1) The number of operators in the expression [default: 9]
2) The value of the first operand [1] 1. The number of operators in the expression [default: 9]
3) The (possibly negative) increment to the next operand [1] 2. The value of the first operand [1]
4) The goal value or 0/0 [42] 3. The (possibly negative) increment to the next operand [1]
4. The goal value or 0/0 [42]
On ANSI/ISO C conformant systems (where long is at least 32 bits) On ANSI/ISO C conformant systems (where long is at least 32 bits)
overflow will occur in the default case (first operand 1, increment 1) overflow will occur in the default case (first operand 1, increment 1)
@@ -116,28 +135,29 @@ systems the first parameter must not exceed 15.
If long is at least 64 bits overflow will occur for more than 19 If long is at least 64 bits overflow will occur for more than 19
operators but you will probably wait quite some time for every of the operators but you will probably wait quite some time for every of the
4^19 = 274,877,906,944 combinations to be evaluated... While I'm at it, `4^19 = 274,877,906,944` combinations to be evaluated... While I'm at it,
on a 50 MHz sparc, 4^11 expressions are evaluated in about 3 cpu on a 50 MHz SPARC, `4^11` expressions are evaluated in about 3 cpu
minutes (gcc -O3). minutes (`gcc -O3`).
Sample arguments: ### Sample arguments:
-----------------
$ ./schweikh2 6 ```sh
$ ./schweikh2 7 0 $ ./schweikh2 6
$ ./schweikh2 7 7 0 $ ./schweikh2 7 0
$ ./schweikh2 8 9 -1 -67/21 $ ./schweikh2 7 7 0
$ ./schweikh2 8 2 2/5 -98/25 $ ./schweikh2 8 9 -1 -67/21
$ ./schweikh2 2 1/0 1 1/0 $ ./schweikh2 8 2 2/5 -98/25
$ ./schweikh2 2 1/0 1 1/0
```
Miscellaneous ### Miscellaneous
-------------
The diamond pattern can be continued without a break. The diamond pattern can be continued without a break.
For a nice printout try this on your Bourne compatible shell: For a nice printout try this on your Bourne compatible shell:
```sh
% while :; do grep -v '#' schweikh2.c; done % while :; do grep -v '#' schweikh2.c; done
```
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License: