diff --git a/2006/hamre/README.md b/2006/hamre/README.md index d1225abd9..7e16f495f 100644 --- a/2006/hamre/README.md +++ b/2006/hamre/README.md @@ -15,7 +15,7 @@ make ### Try: ```sh -./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2' +./try.sh ``` @@ -37,10 +37,10 @@ numbers](https://en.wikipedia.org/wiki/Rational_number). Believe it or not, that is a useful tool to have around, and I haven't found a useful version, much less an obfuscated one. -It is rather feature complete as [rational calculators go. The +It is rather feature complete as rational calculators go. The supported operators are: `+`, `-` (binary and unary), `*`, `/` and `()`. Run it by supplying an expression as the first argument, and the normalized -result will be written to stdout. +result will be written to `stdout`. ```sh ./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2' diff --git a/2006/hamre/try.sh b/2006/hamre/try.sh new file mode 100755 index 000000000..fe123581b --- /dev/null +++ b/2006/hamre/try.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2006/hamre +# + +# 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 "$ ./hamre '-1*42/3*(42*42*42)/42'" 1>&2 +./hamre '-1*42/3*(42*42*42)/42' +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo "$ ./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2'" 1>&2 +./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2' +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo "$ ./hamre '1/0' 1>&2" 1>&2 +./hamre '1/0' 1>&2 +echo 1>&2 +echo "...why did you not get an answer?" 1>&2 +echo 1>&2 + +LIFE=12 +UNIVERSE=15 +EVERYTHING=15 +read -r -n 1 -p "Press any key to continue: " +echo "For the next two notice how similar they are: why do they give different answers?" 1>&2 + +echo "$ LIFE=12; UNIVERSE=15; EVERYTHING=15; ./hamre \"\$LIFE/\$UNIVERSE/\$EVERYTHING\"" 1>&2 +./hamre "$LIFE/$UNIVERSE/$EVERYTHING" + +echo "$ LIFE=12; UNIVERSE=15; EVERYTHING=15; ./hamre \"\$LIFE / \$UNIVERSE / \$EVERYTHING\"" 1>&2 +./hamre "$LIFE / $UNIVERSE / $EVERYTHING" + +echo 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo "And why do these next two give different answers?" 1>&2 +echo "$ LIFE=12; UNIVERSE=15; EVERYTHING=15; ./hamre \"\$LIFE + \$UNIVERSE + \$EVERYTHING\"" 1>&2 +./hamre "$LIFE + $UNIVERSE + $EVERYTHING" +echo "$ LIFE=12; UNIVERSE=15; EVERYTHING=15; ./hamre \"\$LIFE+\$UNIVERSE+\$EVERYTHING\"" 1>&2 +./hamre "$LIFE+$UNIVERSE+$EVERYTHING" + +echo "As it turns out, \$LIFE+\$UNIVERSE+\$EVERYTHING == 42/1 == 42!" 1>&2 + +exit 0 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 5744dc307..53721d8f2 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2964,6 +2964,8 @@ implicitly linked in. Cody fixed this so that it will not crash without an arg after it was suggested this should be fixed. +Cody also added the [try.sh](2006/hamre/try.sh) script. + ## [2006/monge](2006/monge/monge.c) ([README.md](2006/monge/README.md]))