URL and format fix 1996/schweikh2/README.md
This commit is contained in:
1 parent
231ab04074
commit
2f04c16b00
1 file changed
+66
-46
+66
-46
@@ -1,20 +1,24 @@
|
||||
# Best Algorithm
|
||||
|
||||
Jens Schweikhardt
|
||||
DFN Network Operation Center
|
||||
Schlartaeckerweg 3 (home address)
|
||||
D-71384 Weinstadt
|
||||
Germany
|
||||
Jens Schweikhardt
|
||||
DFN Network Operation Center
|
||||
Schlartaeckerweg 3 (home address)
|
||||
D-71384 Weinstadt
|
||||
Germany
|
||||
<http://www.schweikhardt.net>
|
||||
|
||||
http://www.uni-stuttgart.de/People/schweikhardt/home.html
|
||||
|
||||
## To build:
|
||||
|
||||
make all
|
||||
```sh
|
||||
make all
|
||||
```
|
||||
|
||||
## To run:
|
||||
|
||||
./schweikh2
|
||||
```sh
|
||||
./schweikh2
|
||||
```
|
||||
|
||||
The program accepts up to 4 parameters:
|
||||
|
||||
@@ -29,11 +33,25 @@ The program accepts up to 4 parameters:
|
||||
|
||||
## 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?
|
||||
|
||||
./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:
|
||||
|
||||
@@ -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
|
||||
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.
|
||||
|
||||
@@ -79,34 +99,33 @@ modem noise.
|
||||
|
||||
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
|
||||
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. A further obfuscation is the use of 10 instead of '\n'.
|
||||
'\n' can not be constructed by token pasting, AFAIK. That's why `schweikh2`
|
||||
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. A further obfuscation is the use of `10` instead of `'\n'`.
|
||||
`'\n'` can not be constructed by token pasting, AFAIK. That's why `schweikh2`
|
||||
is likely to produce occasional garbage on non-ASCII execution character
|
||||
set systems.
|
||||
|
||||
|
||||
What this program does:
|
||||
-----------------------
|
||||
### What this program does
|
||||
|
||||
The program is an expression evaluator for a limited class of
|
||||
expressions. Known operators are + - * /, operands are real numbers
|
||||
(integers or fractions). The operands are restricted in that they must
|
||||
differ by a constant value, for example 1 + 2 * 3 / 4 - 5. For any
|
||||
combination of operators the expression is evaluated and compared to a
|
||||
goal value. If they compare equal the expression is printed. If the goal
|
||||
value is specified as 0/0 all expressions and results are printed. For
|
||||
any fraction, the numerator and denominator are divided by their
|
||||
greatest common divisor.
|
||||
The program is an expression evaluator for a limited class of expressions. Known
|
||||
operators are `+` `-` `*` `/`; operands are real numbers (integers or
|
||||
fractions). The operands are restricted in that they must differ by a constant
|
||||
value, for example `1 + 2 * 3 / 4 - 5`. For any combination of operators the
|
||||
expression is evaluated and compared to a goal value. If they compare equal the
|
||||
expression is printed. If the goal value is specified as `0/0` all expressions
|
||||
and results are printed. For any fraction, the numerator and denominator are
|
||||
divided by their greatest common divisor.
|
||||
|
||||
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]
|
||||
3) The (possibly negative) increment to the next operand [1]
|
||||
4) The goal value or 0/0 [42]
|
||||
|
||||
1. The number of operators in the expression [default: 9]
|
||||
2. The value of the first operand [1]
|
||||
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)
|
||||
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
|
||||
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,
|
||||
on a 50 MHz sparc, 4^11 expressions are evaluated in about 3 cpu
|
||||
minutes (gcc -O3).
|
||||
`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
|
||||
minutes (`gcc -O3`).
|
||||
|
||||
Sample arguments:
|
||||
-----------------
|
||||
### Sample arguments:
|
||||
|
||||
$ ./schweikh2 6
|
||||
$ ./schweikh2 7 0
|
||||
$ ./schweikh2 7 7 0
|
||||
$ ./schweikh2 8 9 -1 -67/21
|
||||
$ ./schweikh2 8 2 2/5 -98/25
|
||||
$ ./schweikh2 2 1/0 1 1/0
|
||||
```sh
|
||||
$ ./schweikh2 6
|
||||
$ ./schweikh2 7 0
|
||||
$ ./schweikh2 7 7 0
|
||||
$ ./schweikh2 8 9 -1 -67/21
|
||||
$ ./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.
|
||||
For a nice printout try this on your Bourne compatible shell:
|
||||
|
||||
|
||||
% while :; do grep -v '#' schweikh2.c; done
|
||||
```sh
|
||||
% while :; do grep -v '#' schweikh2.c; done
|
||||
```
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
|
||||
Reference in new issue
Block a user