Add 2001/schweikh/try.sh + format/typo checks
This commit is contained in:
1 parent
0496a69ca5
commit
be64048e3d
3 files changed
+34
-9
No files matched your search
@@ -41,9 +41,7 @@ That's not a bug, that's a feature.
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./schweikh foo 'f??'; echo $?
|
||||
./schweikh 'best short program' '??st*o**p?*'; echo $?
|
||||
./schweikh bar 'f??'; echo $?
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -64,7 +62,7 @@ the whole string, so you may want to use `*` at the beginning and end of the
|
||||
pattern if you are looking for something in the middle.
|
||||
|
||||
You can use it for your shell scripting needs similar to a silent grep
|
||||
(and without stdout redirected to `/dev/null`):
|
||||
(and without `stdout` redirected to `/dev/null`):
|
||||
|
||||
```sh
|
||||
if prog "${VARIABLE}" '<glob>'; then
|
||||
@@ -83,15 +81,15 @@ All obfuscation is obviously in the recursive `m()` function, an 86
|
||||
character glob pattern evaluator, returning nonzero for a match:
|
||||
|
||||
* Just a single complex return expression.
|
||||
* Nested ternary operator `?:` to save on if/else verbosity.
|
||||
* Short circuiting `&&` and `||` to save even more on if/else verbosity.
|
||||
* Nested ternary operator `?:` to save on `if`/`else` verbosity.
|
||||
* Short circuiting `&&` and `||` to save even more on `if`/`else` verbosity.
|
||||
* Subtraction instead of an equality operator in `*t - 42`.
|
||||
* ASCII codes for `*` and `?`.
|
||||
* Careful use of blanks even though this year's rules have extended
|
||||
that resource limit.
|
||||
* The source is a complete preprocessed C program. Because it communicates
|
||||
with the world out there by means of argv and the exit status, there
|
||||
is no need for stdio bloat. An asm guru could surely squeeze this
|
||||
with the world out there by means of `argv` and the exit status, there
|
||||
is no need for `stdio.h` bloat. An asm guru could surely squeeze this
|
||||
program in less than a screenful.
|
||||
* `indent(1)` is probably not too helpful.
|
||||
|
||||
@@ -101,7 +99,7 @@ backtracking. I could tell you how it works but then I would have to
|
||||
inputs, it will be quite helpful and instructive. Handling of `?` is
|
||||
straightforward; for `*` start out with `*foo` and `foo*` against `foo`.
|
||||
How does it deal with sequences of adjacent `*`? How could this be
|
||||
improved? If all else fails, recode the `?:` operators with if/else and
|
||||
improved? If all else fails, recode the `?:` operators with `if`/`else` and
|
||||
try again. For extra credit implement character classes like `[a-z]`.
|
||||
|
||||
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2001/schweikh
|
||||
#
|
||||
|
||||
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||
# this way allows us to have the user specify a different compiler in an easy
|
||||
# way.
|
||||
if [[ -z "$CC" ]]; then
|
||||
CC="cc"
|
||||
fi
|
||||
|
||||
make CC="$CC" all >/dev/null || exit 1
|
||||
|
||||
# clear screen after compilation so that only the entry is shown
|
||||
clear
|
||||
|
||||
echo "$ ./schweikh foo 'f??'; echo \$?" 1>&2
|
||||
./schweikh foo 'f??'; echo $?
|
||||
|
||||
echo "$ ./schweikh 'best short program' '??st*o**p?*'; echo \$?" 1>&2
|
||||
./schweikh 'best short program' '??st*o**p?*'; echo $?
|
||||
|
||||
echo "$ ./schweikh bar 'f??'; echo \$?" 1>&2
|
||||
./schweikh bar 'f??'; echo $?
|
||||
@@ -2587,6 +2587,8 @@ Cody fixed this to not crash if not enough args as this was not documented by
|
||||
the author. The other problems are documented so were not fixed. See
|
||||
README.md for details.
|
||||
|
||||
Cody also added the [try.sh](2001/schweikh/try.sh) script.
|
||||
|
||||
|
||||
## [2001/westley](2001/westley/westley.c) ([README.md](2001/westley/README.md]))
|
||||
|
||||
|
||||
Reference in new issue
Block a user