diff --git a/2013/dlowe/.gitignore b/2013/dlowe/.gitignore index 359a2057a..ed369cb9f 100644 --- a/2013/dlowe/.gitignore +++ b/2013/dlowe/.gitignore @@ -1,5 +1,8 @@ +1.txt +2.txt dlowe dlowe.orig fun +ioccc.txt prog.orig sparkl diff --git a/2013/dlowe/README.md b/2013/dlowe/README.md index dfecf6eeb..2ec748179 100644 --- a/2013/dlowe/README.md +++ b/2013/dlowe/README.md @@ -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. diff --git a/2013/dlowe/demo.sh b/2013/dlowe/demo.sh deleted file mode 100755 index 6bf7ca29a..000000000 --- a/2013/dlowe/demo.sh +++ /dev/null @@ -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 diff --git a/2013/dlowe/diff.sh b/2013/dlowe/diff.sh new file mode 100755 index 000000000..bdeb9527a --- /dev/null +++ b/2013/dlowe/diff.sh @@ -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 diff --git a/2013/dlowe/sflen.sh b/2013/dlowe/sflen.sh deleted file mode 100755 index 8cf09b2ff..000000000 --- a/2013/dlowe/sflen.sh +++ /dev/null @@ -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)" diff --git a/2013/dlowe/slflen.sh b/2013/dlowe/slflen.sh new file mode 100755 index 000000000..399051543 --- /dev/null +++ b/2013/dlowe/slflen.sh @@ -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 diff --git a/2013/dlowe/try.sh b/2013/dlowe/try.sh new file mode 100755 index 000000000..9ff30282b --- /dev/null +++ b/2013/dlowe/try.sh @@ -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 diff --git a/bugs.md b/bugs.md index 1b20321e6..73848bf82 100644 --- a/bugs.md +++ b/bugs.md @@ -2876,6 +2876,12 @@ exercise to see if you understand the code. You can try and answer the questions, too: when will it crash? When will it draw something funny (or will it? :-) ) and when will it just do nothing? +The author also stated: + +* Produces bogus graphs when given > about 5000 arguments. +* Only works if your terminal is UTF-8 and your font supports the 8 glyphs + used. + ## 2013 hou diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index e7faa406e..7f7d143ff 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3541,20 +3541,24 @@ author linked to at `https://bitly.com/1bU8URK`. different compilers as [fun.c](2013/dlowe/fun.c). He modified the Makefile so that running `make all` will compile it, saving you the effort. -He also provided the script [sflen.sh](2013/dlowe/sflen.sh), fixing it for -shellcheck, which is based on the author's remarks, giving a script that shows -the spark line of the file lengths (as in `wc -c`). These fixes were applied in -the author's remarks as well. +He also provided the script [slflen.sh](2013/dlowe/slflen.sh) which is based on +the author's remarks, fixing it for shellcheck and improving upon it (show what +files will be processed). This script shows the sparkline of the file lengths +(as in `wc -c`). The fixes (but not the improvements) were added to the author's +remarks. Since the author called the program `sparkl` Cody modified the Makefile so that running `make all` will create a symlink to `dlowe` as `sparkl`. Running `make clobber` will delete both and running `make clobber all` will ensure that the -symlink is created. The `sflen.sh` script also explicitly makes sure to create +symlink is created. The `slflen.sh` script also explicitly makes sure to create the symlink as it uses it, even though it runs `make clobber all`. Cody also added the [try.sh](2013/dlowe/try.sh) script to more easily try the program. +He also added the [diff.sh](2013/dlowe/diff.sh) script which is based on some +commands to try that he suggested to see how different lengths look. + ## [2013/endoh2](2013/endoh2/endoh2.c) ([README.md](2013/endoh2/README.md))