From 70bb65f47ebc235b3dc6457424fcc71db468ea57 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 11 Dec 2023 06:43:51 -0800 Subject: [PATCH] Add try scripts to 2018/ferguson + formatting The try.sh and try.alt.sh scripts are respectively for the entry and the alt code. There is a joke in them that is based on what the judges originally suggested one try. The weasel.man page was deleted. Instead weasel.1 has had the FILES section removed (which caused some confusion in another way with another winner of that year). The spec file will have to be tested again another time. I did NOT format / typo check the README.md file. Too much to do for now and since it's mine I can do it any other time. I'd like to get through the rest of the entries. Thus this should complete (for now?) 2018/ferguson. --- 2018/ferguson/FILES | 15 +-- 2018/ferguson/Makefile | 2 +- 2018/ferguson/README.md | 38 ++++++-- 2018/ferguson/test.sh | 2 +- 2018/ferguson/try.alt.sh | 52 +++++++++++ 2018/ferguson/try.sh | 52 +++++++++++ 2018/ferguson/weasel.1 | 34 ------- 2018/ferguson/weasel.man | 192 --------------------------------------- thanks-for-help.md | 3 +- 9 files changed, 137 insertions(+), 253 deletions(-) create mode 100755 2018/ferguson/try.alt.sh create mode 100755 2018/ferguson/try.sh delete mode 100644 2018/ferguson/weasel.man diff --git a/2018/ferguson/FILES b/2018/ferguson/FILES index f3c62578f..99da7dcf1 100644 --- a/2018/ferguson/FILES +++ b/2018/ferguson/FILES @@ -24,20 +24,7 @@ Makefile The Makefile that simplifies compilation as well as itself [1]. -weasel.man The local version of the man page; that is if it's - not installed. You can still use 'man' on the - 'weasel.1' file but 'weasel.man' references - different file paths from 'weasel.1'. - - -weasel.1 The system wide version of the man page for when - (if) it's installed [2]. Note that the suggested - invocation 'man -l ./weasel.man' can be replaced - with 'man -l ./weasel.1' too but if the weasel - package is installed 'man weasel.1' (note the - missing '-l ./') would read the from the system - man page. - +weasel.1 The man page for weasel. README.md The source of the index.html file [3]. diff --git a/2018/ferguson/Makefile b/2018/ferguson/Makefile index f1671da73..40d9ad489 100644 --- a/2018/ferguson/Makefile +++ b/2018/ferguson/Makefile @@ -109,7 +109,7 @@ PROG= prog # OBJ= ${PROG}.o CSRC= ${PROG}.o -DATA= FILES hint.css rpm.md test-strings.txt weasel.1 weasel.man weasel.spec +DATA= FILES hint.css rpm.md test-strings.txt weasel.1 weasel.spec TARGET= ${PROG} weasel # ALT_OBJ= ${PROG}.alt diff --git a/2018/ferguson/README.md b/2018/ferguson/README.md index 8dbdde50e..1749a62a5 100644 --- a/2018/ferguson/README.md +++ b/2018/ferguson/README.md @@ -4,6 +4,9 @@ make ``` +The author provided an alternate version which has a simpler keyboard for the +monkey Eric. See [Alternate code](#alternate-code) below. + ## To use: @@ -15,20 +18,35 @@ make ### Try: ```sh -./weasel words -./weasel -mq words -./weasel -q -r8 'EVOLUTION IS A PROVEN FACT' -./weasel -m 'INTELLIGENT DESIGN' - -make test +./try.sh ``` ## Alternate code: -The author provided an alternate version which has a simpler keyboard for the -monkey Eric. See his comments under the 'keyboards' section, briefly referred to -in the 'what it is' section. +This version has a simpler keyboard (fewer characters). The author wrote more +about this under the [keyboards](#keyboards) section, briefly referred to in the +[what it is](#what) section. + + +### Alternate build: + + +```sh +make alt +``` + + +### Alternate use: + +Use `weasel.alt` as you would `weasel` above. + + +### Alternate try: + +```sh +./try.alt.sh +``` ## Judges' remarks: @@ -50,7 +68,7 @@ while using more Cenozoic minded code migration, read rpm.md. If you find yourself in an evolutionary dead end, try: ```sh -man ./weasel.man +man ./weasel.1 ``` diff --git a/2018/ferguson/test.sh b/2018/ferguson/test.sh index c7823ea7e..77c62b13f 100755 --- a/2018/ferguson/test.sh +++ b/2018/ferguson/test.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Make sure the program has been compiled -make clobber all 1> /dev/null|| exit 1 +make everything 1> /dev/null|| exit 1 while read -r f; do ./weasel "$@" "${f}" # full line because of quotes diff --git a/2018/ferguson/try.alt.sh b/2018/ferguson/try.alt.sh new file mode 100755 index 000000000..83713b706 --- /dev/null +++ b/2018/ferguson/try.alt.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# try.alt.sh - demonstrate IOCCC winner 2018/ferguson alt code +# + +# 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" alt >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +read -r -n 1 -p "Press any key to run: ./weasel.alt words (space = next page, q = quit): " +echo 1>&2 +time ./weasel.alt words | less -EXF + +read -r -n 1 -p "Press any key to see how long it'll take Eric the monkey to type his name: " +echo 1>&2 +time ./weasel.alt -mq Eric +echo 1>&2 + +read -r -n 1 -p "Press any key to run: make test: " +echo 1>&2 +make test + +read -r -p "Do you wish to try and prove 'intelligent design' (Y/N)? " +if [[ "$REPLY" == "Y" || "$REPLY" == "y" ]]; then + echo "$ ./weasel.alt -m 'INTELLIGENT DESIGN'" 1>&2 + echo "Press any key to continue. Send ctrl-c when convinced that intelligent" 1>&2 + read -r -n 1 -p "design is not real or you're tired of waiting: " + echo 1>&2 + time ./weasel.alt -m 'INTELLIGENT DESIGN' + echo 1>&2 +else + echo "$ ./weasel.alt -q -r8 'EVOLUTION IS A PROVEN FACT'" 1>&2 + time ./weasel.alt -q -r8 'EVOLUTION IS A PROVEN FACT' +fi + +read -r -n 1 -p "Do you want to see how long it might take the monkey Eric to type 'words'? (Y/N)? " +if [[ "$REPLY" == "Y" || "$REPLY" == "y" ]]; then + echo 1>&2 + echo "Will not display until Eric succeeds or too many generations. Hit ctrl-c" 1>&2 + echo "to stop him early." 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + time ./weasel.alt -mq words +fi diff --git a/2018/ferguson/try.sh b/2018/ferguson/try.sh new file mode 100755 index 000000000..9552e1e21 --- /dev/null +++ b/2018/ferguson/try.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2018/ferguson +# + +# 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 + +read -r -n 1 -p "Press any key to run: ./weasel words (space = next page, q = quit): " +echo 1>&2 +time ./weasel words | less -EXF + +read -r -n 1 -p "Press any key to see how long it'll take Eric the monkey to type his name: " +echo 1>&2 +time ./weasel -mq Eric +echo 1>&2 + +read -r -n 1 -p "Press any key to run: make test: " +echo 1>&2 +make test + +read -r -p "Do you wish to try and prove 'intelligent design' (Y/N)? " +if [[ "$REPLY" == "Y" || "$REPLY" == "y" ]]; then + echo "$ ./weasel -m 'INTELLIGENT DESIGN'" 1>&2 + echo "Press any key to continue. Send ctrl-c when convinced that intelligent" 1>&2 + read -r -n 1 -p "design is not real or you're tired of waiting: " + echo 1>&2 + time ./weasel -m 'INTELLIGENT DESIGN' + echo 1>&2 +else + echo "$ ./weasel -q -r8 'EVOLUTION IS A PROVEN FACT'" 1>&2 + time ./weasel -q -r8 'EVOLUTION IS A PROVEN FACT' +fi + +read -r -n 1 -p "Do you want to see how long it might take the monkey Eric to type 'words'? (Y/N)? " +if [[ "$REPLY" == "Y" || "$REPLY" == "y" ]]; then + echo 1>&2 + echo "Will not display until Eric succeeds or too many generations. Hit ctrl-c" 1>&2 + echo "to stop him early." 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + time ./weasel -mq words +fi diff --git a/2018/ferguson/weasel.1 b/2018/ferguson/weasel.1 index 1d19b133d..3b6e62b65 100644 --- a/2018/ferguson/weasel.1 +++ b/2018/ferguson/weasel.1 @@ -135,40 +135,6 @@ was disabled as above). Observe that here the \fB-r5-q\fP doesn't prevent the quiet output from being enabled; on the other hand the options \fB-r5- -q -- -r10\fP would! .RE -.SH FILES -\fI/usr/src/weasel/weasel.c\fP -.RS -The source code to the \fBweasel\fP program. -.RE -.PP -\fI/usr/src/weasel/weasel.alt.c\fP -.RS -The source code to the \fBweasel.alt\fP program. -.RE -.PP -\fI/usr/src/weasel/Makefile\fP -.RS -The Makefile to compile the source code should you wish to compile the -source code files. -.RE -.PP -\fI/usr/src/weasel/test.sh\fP -.RS -A test script that demonstrates the weasel program (this script is used -by \fBmake test\fP) by reading in strings, one at a time, and invoking -the program with that string as the target chromosome. See the -\fIREADME.md\fP or \fIhint.html\fP for more details on using this script. -.RE -.PP -\fI/usr/src/weasel/test-strings.txt\fP -.RS -The data file the \fItest.sh\fP script reads strings from. -.RE -.PP -\fI/usr/share/doc/weasel/weasel.html\fP, \fI/usr/share/doc/weasel/weasel.markdown\fP -.RS -More detailed documentation. -.RE .SH HINTS The IOCCC judges in 2018 asked the following in the guidelines: .RS diff --git a/2018/ferguson/weasel.man b/2018/ferguson/weasel.man deleted file mode 100644 index 30d6fa400..000000000 --- a/2018/ferguson/weasel.man +++ /dev/null @@ -1,192 +0,0 @@ -.TH weasel 1 "15 February 2023" "weasel" "IOCCC 2018" -.SH NAME -weasel \- The IOCCC 2018 Implementation of Richard Dawkins's Weasel program -.SH SYNOPSIS -\fBweasel\fP [\fI\-r\fP] [\fI\-m\fP] [\fI\-q\fP] [<\fIchromosomal string\fP>] -.PP -\fBweasel.alt\fP [\fI\-r\fP] [\fI\-m\fP] [\fI\-q\fP] [<\fIchromosomal string\fP>] -.SH DESCRIPTION -\fBweasel\fP is an obfuscated implementation of Richard Dawkins' \fIWeasel program\fP. -According to Wikipedia in chapter three of his book \fIThe Blind Watchmaker\fP Dawkins wrote: -.PP -.RS -I don't know who it was first pointed out that, given enough time, -a monkey bashing away at random on a typewriter could produce all -the works of Shakespeare. The operative phrase is, of course, given -enough time. Let us limit the task facing our monkey somewhat. -Suppose that he has to produce, not the complete works of Shakespeare -but just the short sentence 'Methinks it is like a weasel', and we -shall make it relatively easy by giving him a typewriter with a -restricted keyboard, one with just the 26 (capital) letters, and -a space bar. How long will he take to write this one little sentence? -.RE -.PP -He refers to the \fIInfinite Monkey Theorem\fP in particular and as he -points out it is \fBgiven enough time.\fP The weasel program uses a \fIgenetic -algorithm (GA)\fP to intelligently come to a conclusion but this implementation -has several additions: \fBtwo Easter eggs,\fP a \fBquiet output mode,\fP -an \fBoption to change the mutation rate\fP as well as the ability to -\fBspecify the chromosomal string.\fP -Furthermore the keyboard isn't as limited as Dawkins's implementation. -The \fBweasel.alt\fP keyboard is a more limited keyboard but not -as limited as Dawkins's Weasel program keyboard. -.SH OPTIONS -.PP -\fB\-r\fP\fI\fP -This sets the mutation rate to \fI\fP; valid range is 1 through 100. -Anything outside this range will disable the genetic algorithm and simulate -a monkey in front of a typewriter. -If a valid mutation rate is set after this then the monkey typewriter mode -will be disabled but if monkey mode has been explicitly requested by the -\fB\-m\fP option the mutation rate is ignored. -Note that there cannot be a space between the \fB\-r\fP and \fI\fP. -The default is 1; valid range is >= 1 && <= 100. -.PP -\fB\-m\fP -Set monkey mode. This disables the genetic algorithm and is disables the -mutation rate entirely; instead it will pseudo-randomly select a character -from the keyboard in every offspring for every generation and selection -will not take place: parents are simply the first two offspring -regardless of their fitness score. Once this is enabled you -cannot disable it: be wary of the typing monkeys! -.PP -\fB\-q\fP -Quiet output. -Only display settings like mutation rate, quiet output, -target string and the final answer - if it comes to one. -Just like monkey mode you cannot disable this once it's been enabled. -.PP -\fB--\fP -Disable parsing of additional options (but not target strings); see -.B EXAMPLES -for a subtle point. -.SH EXIT STATUS -On error of any kind (including reaching the maximum number of attempts) -return 1; otherwise return 0. -.SH BUGS -Bugs? What's this? :) Any bugs are actually insolent monkeys tampering -with the program! But if you insist I do include errata on my website. -.SH EXAMPLES -.PP -\fBweasel\fP -.PP -.NF -Using the GA with the default mutation rate of 1 and output mode (verbose) -look for the default string in Hawkins's Weasel program; note that in -all cases the string to be found is capitalised. -.FI -.PP -\fBweasel \-qr5 -weasel \-q \-r5\fP -.NF -.PP -Enables quiet output and sets a mutation rate of 5. -.PP -.FI -\fBweasel \-rqr10\fP -.NF -.PP -First sets an invalid mutation rate, then enables quiet output and -finally sets (a valid) mutation rate of 10. -.FI -.PP -.NF -\fBweasel \-m 'I AM A MONKEY TYPING'\fP -.PP -.FI -Simulate a monkey typing at the typewriter trying to type out the -string \fBI AM A MONKEY TYPING\fP without quotes. Note that this will -take some time almost assuredly and you might fall asleep before -the monkey succeeds. Here you would see all the attempts because -quiet output was not requested. -.PP -\fBweasel I AM NOT A MONKEY\fP -.PP -.NF -Using the GA find the final string specified (this always happens); -because the string wasn't quoted the program will have seen each word -as a separate argument and thus it would search for \fBMONKEY\fP. -.FI -.PP -\fBweasel '"WEASEL"'\fP -.PP -.NF -Search for the string \fB"WEASEL"\fP including double quotes ("s). -.FI -.PP -\fBweasel "'WEASEL'"\fP -.PP -.NF -Search for the string \fB'WEASEL'\fP including the single quotes ('s). -.FI -.PP -\fBweasel \-q \-r5 \-\- \-r10\fP -.PP -.NF -Enable quiet output, set mutation rate to 5, disable further option parsing -and set target string to \fB-r10\fP (literally because option parsing was disabled). -.FI -.PP -\fBweasel \-r5\-q \-\- \-r10\fP -.PP -Set mutation rate to 5, enable quiet output, disable further parsing of -options and set target string to \fB-r10\fP (literally - because option parsing -was disabled as above). Observe that here the \fB-r5-q\fP doesn't prevent the -quiet output from being enabled; on the other hand the options -\fB-r5- -q -- -r10\fP would! -.RE -.SH FILES -\fIprog.c\fP -.RS -The source code to the \fBweasel\fP program. -.RE -.PP -\fIprog.alt.c\fP -.RS -The source code to the \fBweasel.alt\fP program. -.RE -.PP -\fIMakefile\fP -.RS -The Makefile to compile the source code should you wish to compile the -source code files. -.RE -.PP -\fItest.sh\fP -.RS -A test script that demonstrates the weasel program (this script is used -by \fBmake test\fP) by reading in strings, one at a time, and invoking -the program with that string as the target chromosome. See the -\fIREADME.md\fP or \fIhint.html\fP for more details on using this script. -.RE -.PP -\fItest-strings.txt\fP -.RS -The data file the \fItest.sh\fP script reads strings from. -.RE -.PP -\fIhint.html\fP, \fIREADME.md\fP -.RS -More detailed documentation. -.RE -.SH HINTS -The IOCCC judges in 2018 asked the following in the guidelines: -.RS -.PP -\fBBTW: What is so special about 2305567963945518424753102147331756070? You tell us!\fP -.RE -.PP -It is the primorial prime of 97; but can you find a way to get the program -to by default search for this number instead? You might need the source code to -find it! -.SH SEE ALSO -.NF -<\fBhttps://ioccc.xexyl.net/2018/weasel\fP> -.PP -<\fBhttps://en.wikipedia.org/wiki/Infinite_monkey_theorem\fP> -.PP -<\fBhttps://en.wikipedia.org/wiki/Weasel_program\fP> -.PP -<\fBhttps://web.archive.org/web/20180308131613/http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol1/hmw/article1.html\fP> -.SH AUTHOR -Cody Boone Ferguson <\fBweasel@xexyl.net\fP> diff --git a/thanks-for-help.md b/thanks-for-help.md index a3b85ceb0..4b865c37b 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -3954,7 +3954,8 @@ He also added the [try.sh](/2015/yang/try.sh) script. [Cody](#cody), with irony well intended :-), fixed the [test.sh script](/2018/ferguson/test.sh) for portability, shellcheck, making it executable and other things, fixed dead links in the man page, updated the test-strings.txt -file and other things as well. +file and other things as well (like adding the [try.sh](/2018/ferguson/try.sh) +and [try.alt.sh](/2018/ferguson/try.alt.sh) scripts). Landon notes that Cody will probably never finish changes in his entries and that's probably true: let's just say that for the IOCCC I'm (Cody) a weasel! :-)