Add 2006/hamre/try.sh + formatting/typo checks

This commit is contained in:
Cody Boone Ferguson committed 2023-11-24 05:20:12 -08:00
1 parent b1a57fd2af
commit 6c1c6dc5a4
3 files changed
+63 -3

No files matched your search

+3 -3
View File
@@ -15,7 +15,7 @@ make
### Try: ### Try:
```sh ```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 is a useful tool to have around, and I haven't found a useful version, much less
an obfuscated one. 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 supported operators are: `+`, `-` (binary and unary), `*`, `/` and `()`. Run it
by supplying an expression as the first argument, and the normalized by supplying an expression as the first argument, and the normalized
result will be written to stdout. result will be written to `stdout`.
```sh ```sh
./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2' ./hamre '-1+4/3*(2+1/(3/2*(7/2-7/3+1/6)))/2'
+58
View File
@@ -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
+2
View File
@@ -2964,6 +2964,8 @@ implicitly linked in.
Cody fixed this so that it will not crash without an arg after it was suggested Cody fixed this so that it will not crash without an arg after it was suggested
this should be fixed. 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])) ## [2006/monge](2006/monge/monge.c) ([README.md](2006/monge/README.md]))