Format 2013/dlowe, new script, rename others etc.

The demo.sh was renamed try.sh to be like the other entries.

The new script diff.sh runs some commands that I had previously added
(to demonstrate the entry) but which would be better in a script.

Renamed sflen.sh (for sparkline file length) to be slflen.sh (for
sparkline file length also).

Updated bugs.md - added more features that the author noted.

Format/typo check README.md file.

This should complete the review of 2013/dlowe.
This commit is contained in:
Cody Boone Ferguson committed 2023-12-04 07:48:23 -08:00
1 parent a6a108c57b
commit c5b831f3a0
9 files changed
+109 -70

No files matched your search

+3
View File
@@ -1,5 +1,8 @@
1.txt
2.txt
dlowe
dlowe.orig
fun
ioccc.txt
prog.orig
sparkl
+16 -40
View File
@@ -19,33 +19,23 @@ For more detailed information see [2013 dlowe in bugs.md](/bugs.md#2013-dlowe).
## To use:
```sh
./dlowe [numbers...]
./dlowe [word...]
```
where `[word...]` is one or more words including numbers or otherwise.
### Try:
```sh
./dlowe 0 1 2 3 4 5 6 7
./dlowe 16 32 64 128
./dlowe 16 32 64 128 256
./dlowe 16 32 64 128 256 512
./dlowe 0
echo "sparkline of file sizes: $(wc -c * | awk '{print $1}' | xargs ./dlowe)" # or ./sflen.sh
```
Alternatively, for the lazy or those short on time, try:
```sh
./demo.sh
./try.sh
```
What is different about the above if you do something like:
```sh
echo 'IOCCC 2013' > ioccc.txt
./demo.sh
echo 'IOCCC winning entry 2013/dlowe' > ioccc.txt
./try.sh
rm -f ioccc.txt
```
@@ -54,31 +44,14 @@ rm -f ioccc.txt
To make it simpler to see try showing just the different line like:
```sh
./demo.sh | tail -n 2 > 1.txt
echo 'IOCCC 2013' > ioccc.txt
./demo.sh | tail -n 2 > 2.txt
rm -f ioccc.txt
diff 1.txt 2.txt
rm 1.txt 2.txt
./diff.sh
```
This program will possibly crash or draw something funny with 0 args. Then
again it might not. :-)
This is supposed to happen. As is written in the
[The Jargon File](http://catb.org/jargon/html/F/feature.html):
```
That's not a bug, that's a feature.
```
Ask yourself the following questions: when will it crash, when will it draw
something funny (or will it ? :-) ) and when will it do nothing?
## Judges' remarks:
We liked how this entry used Unicode, specifically UTF-8, in a somewhat obfuscated way.
We liked how this entry used Unicode, specifically UTF-8, in a somewhat
obfuscated way.
Also, why doesn't it crash but instead produces a correct output when called
with one argument or when all arguments are equal?
@@ -140,13 +113,14 @@ $ echo "sparkline of file lengths: $(wc -c * | awk '{print $1}' | xargs ./sparkl
sparkline of file sizes: ▁▁▁▃▃▂▁▂▁▁▉
```
NOTE: this has been provided in [sflen.sh](sflen.sh) so you can try:
NOTE: this has been provided in [slflen.sh](slflen.sh) so you can try:
```sh
./sflen.sh
./slflen.sh
```
instead.
instead (which [try.sh](try.sh) also uses).
### Description
@@ -164,14 +138,16 @@ sense of the shape of your data.
used.
* Produces a few harmless compiler warnings.
### Obfuscation
The code is very terse. I was torn between submitting this version, and a
one-line version compressed using a couple more -D flags.
one-line version compressed using a couple more `-D` flags.
Hand-rolled UTF-8 sequence, magic numbers (what's that 7 for?), meaningless
variable names, reused variables, and so on.
### Acknowledgements
Edward Tufte invented sparklines (among other things.) Brilliant.
-20
View File
@@ -1,20 +0,0 @@
#!/usr/bin/env bash
make all || exit 1
echo "$ ./dlowe 0 1 2 3 4 5 6 7"
./dlowe 0 1 2 3 4 5 6 7
echo
echo "$ ./dlowe 16 32 64 128"
./dlowe 16 32 64 128
echo
echo "$ ./dlowe 16 32 64 128 256"
./dlowe 16 32 64 128 256
echo
echo "$ ./dlowe 16 32 64 128 256 512"
./dlowe 16 32 64 128 256 512
echo
echo "$ ./dlowe 0"
./dlowe 0
echo
echo "$ ./sflen.sh"
./sflen.sh
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# 2013/dlowe/diff.sh - show diff of output of two commands based on different
# number of files (due to total length differing) in the directory
# 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
echo "$ ./try.sh | tail -n 3 > 1.txt" 1>&2
./try.sh | tail -n 3 > 1.txt
echo "$ echo 'IOCCC winning entry 2013/dlowe' > ioccc.txt" 1>&2
echo 'IOCCC winning entry 2013/dlowe' > ioccc.txt
echo "$ ./try.sh | tail -n 3 > 2.txt" 1>&2
./try.sh | tail -n 3 > 2.txt
echo "$ diff 1.txt 2.txt" 1>&2
diff 1.txt 2.txt
rm -f 1.txt 2.txt ioccc.txt
-5
View File
@@ -1,5 +0,0 @@
#!/usr/bin/env bash
make all || exit 1
ln -sf dlowe sparkl
echo "sparkline of file lengths: $(wc -c ./* | awk '{print $1}' | xargs ./sparkl)"
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
#
# 2013/dlowe/slflen.sh - show sparkline length of all files in the current
# working directory
#
# 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
ln -sf dlowe sparkl
ls -1 *
echo -n "sparkline length of above files: "
wc -c ./* | awk '{print $1}' | xargs ./sparkl
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2013/dlowe
#
# 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 "$ ./dlowe 0 1 2 3 4 5 6 7"
./dlowe 0 1 2 3 4 5 6 7
echo
echo "$ ./dlowe 16 32 64 128"
./dlowe 16 32 64 128
echo
echo "$ ./dlowe 16 32 64 128 256"
./dlowe 16 32 64 128 256
echo
echo "$ ./dlowe 16 32 64 128 256 512"
./dlowe 16 32 64 128 256 512
echo
echo "$ ./dlowe 0"
./dlowe 0
echo
echo "$ ./slflen.sh"
./slflen.sh