Add 1996/schweikh2/try.sh + format/typo checks
The try.sh script runs some of the commands in the try section as well as a minimal version of something the author recommends one trying for a pleasing effect. The reason it is minimal is because it is an infinite loop and it seems like not a good idea to have an infinite loop in a script that demonstrates a few things of the entry. Format and typo check the README.md file.
This commit is contained in:
1 parent
f704c2989e
commit
94f742eabd
3 files changed
+49
-16
No files matched your search
+22
-16
@@ -25,7 +25,7 @@ The program accepts up to 4 parameters:
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./schweikh2 15 1 0 0/0
|
./try.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
What happens if you pass only three parameters like the below?
|
What happens if you pass only three parameters like the below?
|
||||||
@@ -40,15 +40,20 @@ The author also suggests:
|
|||||||
while :; do grep -v '#' schweikh2.c; done
|
while :; do grep -v '#' schweikh2.c; done
|
||||||
```
|
```
|
||||||
|
|
||||||
(and we do too) which works with `sh`, `bash`, `ksh` and `zsh` as well.
|
(and we do too) which works with `sh`, `bash`, `ksh` and `zsh` as well. Press
|
||||||
|
ctrl-c to stop it. Observe how the [try.sh](try.sh) script does this a number of
|
||||||
|
times.
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
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](hunni.c). The perl script, [hunni.pl](hunni.pl), obfuscates it
|
||||||
|
appropriately. Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
less hunni.c
|
||||||
|
|
||||||
perl ./hunni.pl < hunni.c
|
perl ./hunni.pl < hunni.c
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -60,6 +65,7 @@ This entry was another crowd pleaser at the IOCCC BOF.
|
|||||||
Note: the source must be viewed with tabstop 8. To appreciate the
|
Note: the source must be viewed with tabstop 8. To appreciate the
|
||||||
beauty have your eyes half closed.
|
beauty have your eyes half closed.
|
||||||
|
|
||||||
|
|
||||||
### Why I think this program is obfuscated:
|
### Why I think this program is obfuscated:
|
||||||
|
|
||||||
C is a free format language. It is therefore a question of style how
|
C is a free format language. It is therefore a question of style how
|
||||||
@@ -69,16 +75,16 @@ I put spaces around operators, after opening braces and before closing
|
|||||||
braces. I have generalized this rule by putting whitespace after *any*
|
braces. I have generalized this rule by putting whitespace after *any*
|
||||||
non-white space character (with the exception of preprocessor directives).
|
non-white space character (with the exception of preprocessor directives).
|
||||||
There are no recognizable keywords anymore. There are no recognizable
|
There are no recognizable keywords anymore. There are no recognizable
|
||||||
string literals any more. The main function is invisible. All operators
|
string literals any more. The `main()` function is invisible. All operators
|
||||||
longer than one character have gone. They have been replaced by macro
|
longer than one character are gone. They have been replaced by macro
|
||||||
calls with quite a number of arguments. The keys are the token pasting
|
calls with quite a number of arguments. The keys are the token pasting
|
||||||
and stringizing macros e and O. The "arcane rules of token pasting"
|
and stringizing macros `e` and `O`. The "arcane rules of token pasting"
|
||||||
[K&R2] are used up to three levels, `H(O,r)R(O,r)` (!) which is needed to make
|
[K&R2] are used up to three levels: `H(O,r)R(O,r)` (!) which is needed to make
|
||||||
one 8-character token from 8 characters ('unsigned'). BTW, C has no 9 or
|
one 8-character token from 8 characters (`unsigned`). BTW, C has no 9 or
|
||||||
more character reserved words, so a fourth level is only required if
|
more character reserved words, so a fourth level is only required if
|
||||||
you intend to generate object names from 9 or more components. The final
|
you intend to generate object names from 9 or more components. The final
|
||||||
round even swaps the tokens, so all keywords must be spelled backwards
|
round even swaps the tokens, so all keywords must be spelled backwards
|
||||||
(sort of, can you spot printf in the P macro?).
|
(sort of, can you spot `printf` in the `P` macro?).
|
||||||
|
|
||||||
Try to indent the source. The unbalanced parentheses confuse Solaris'
|
Try to indent the source. The unbalanced parentheses confuse Solaris'
|
||||||
indent to the max (although the result does compile):
|
indent to the max (although the result does compile):
|
||||||
@@ -112,18 +118,18 @@ divided by their 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]
|
1. The number of operators in the expression [default: 9].
|
||||||
2. The value of the first operand [1]
|
2. The value of the first operand [1].
|
||||||
3. The (possibly negative) increment to the next operand [1]
|
3. The (possibly negative) increment to the next operand [1].
|
||||||
4. The goal value or 0/0 [42]
|
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)
|
||||||
only for more than 11 operators. Because a bit mask is used that needs
|
only for more than 11 operators. Because a bit mask is used that needs
|
||||||
twice the number of operands in bits (plus a sentinel value) on those
|
twice the number of operands in bits (plus a sentinel value) on those
|
||||||
systems the first parameter must not exceed 15.
|
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
|
||||||
@@ -142,7 +148,7 @@ minutes (`gcc -O3`).
|
|||||||
|
|
||||||
### 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
|
```sh
|
||||||
|
|||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
make all >/dev/null || exit 1
|
||||||
|
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to to run ./schweikh2: " 1>&2
|
||||||
|
./schweikh2
|
||||||
|
echo >&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to run: ./schweikh2 15 1 0 0/0 | head -n 15: " 1>&2
|
||||||
|
./schweikh2 15 1 0 0/0 | head -n 15
|
||||||
|
echo >&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key one more time: " 1>&2
|
||||||
|
i=0
|
||||||
|
while ((i++<15)); do
|
||||||
|
grep -v '#' schweikh2.c
|
||||||
|
done
|
||||||
@@ -1997,6 +1997,15 @@ on other systems (the other file is
|
|||||||
the Makefile despite the fact that very few probably use Solaris nowadays.
|
the Makefile despite the fact that very few probably use Solaris nowadays.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [1996/schweikh2](1996/schweikh2/schweikh2.c) ([README.md](1996/schweikh2/README.md]))
|
||||||
|
|
||||||
|
Cody added the [try.sh](1996/schweikh2/try.sh) script with a few commands to try
|
||||||
|
along with a shorter version of something the author suggested one try (it is
|
||||||
|
suggested that one try the longer version too but it will run in an infinite
|
||||||
|
loop so having it in a script is less desired).
|
||||||
|
|
||||||
|
|
||||||
## [1996/westley](1996/westley/westley.c) ([README.md](1996/westley/README.md]))
|
## [1996/westley](1996/westley/westley.c) ([README.md](1996/westley/README.md]))
|
||||||
|
|
||||||
Cody fixed a segfault in this entry as well as it displaying environmental
|
Cody fixed a segfault in this entry as well as it displaying environmental
|
||||||
|
|||||||
Reference in new issue
Block a user