Add 2000/natori/try.alt.sh + improve try.sh

The try.alt.sh script is slightly different from try.sh in that the
order is reversed.

The try.sh script now at the end always starts out in a sequence of
northern hemisphere then southern hemisphere so that one can guarantee
to get that form. The try.alt.sh does the same but starts out with the
southern hemisphere first.
This commit is contained in:
Cody Boone Ferguson committed 2024-01-20 05:56:01 -08:00
1 parent e0cde4d7d7
commit 5e25056532
4 files changed
+194 -2

No files matched your search

+15
View File
@@ -22,6 +22,9 @@ version](#alternate-code) below.
./try.sh
```
Try running this on different days, say a few days apart, and each time run it
several times in a row (or several times in a day).
Also try modifying the code so that it will show another Moon phase based on
input or else just by the code itself. Bonus points if you can make it show all~
@@ -47,6 +50,9 @@ make alt
./natori.alt
```
Try running this on different days, say a few days apart, and each time run it
several times in a row (or several times in a day).
What happens if you run it in the northern hemisphere? Are there any
differences?
@@ -54,6 +60,15 @@ Can you identify any Moon phases that result in the same output of both
versions? Or are there any?
### Alternate try:
```sh
./try.alt.sh
```
Like with [try.sh](try.sh), try using this multiple times.
## Judges' remarks:
Here is a nice compact program that changes with the phase of the Moon.
+162
View File
@@ -0,0 +1,162 @@
#!/usr/bin/env bash
#
# try.alt.sh - demonstrate IOCCC winner 2000/natori 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" everything >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
NATORI="natori"
moon()
{
read -r -n 1 -p "Press any key to randomly show the northern/southern hemisphere Moon: "
echo 1>&2
for ((i=0;i<=10;i++)); do
RAND=$((RANDOM % 1000))
if [[ "$RAND" -le 500 ]]; then
./"$NATORI".alt
echo 1>&2
else
./"$NATORI"
echo 1>&2
fi
done
echo 1>&2
RAND=$((RANDOM % 1000))
if [[ "$RAND" -gt 500 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
fi
echo 1>&2
echo "We will now reverse the order." 1>&2
echo 1>&2
if [[ "$RAND" -le 499 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
./"$NATORI"
./"$NATORI".alt
fi
echo 1>&2
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We recommend that you try holding space down." 1>&2
echo 1>&2
RAND=$((RANDOM % 1000))
if [[ "$RAND" -gt 500 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
( ./"$NATORI.alt"; ./"$NATORI" ; ./"$NATORI.alt" ; ./"$NATORI"; \
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
( ./"$NATORI"; ./"$NATORI.alt" ; ./"$NATORI" ; ./"$NATORI.alt"; \
./"$NATORI"; ./"$NATORI.alt" ) | less -rEXF
fi
echo 1>&2
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We now recommend that you try holding enter down." 1>&2
echo 1>&2
if [[ "$RAND" -gt 500 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
( ./"$NATORI.alt"; ./"$NATORI" ; ./"$NATORI.alt" ; ./"$NATORI"; \
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
( ./"$NATORI"; ./"$NATORI.alt" ; ./"$NATORI" ; ./"$NATORI.alt"; \
./"$NATORI"; ./"$NATORI.alt" ) | less -rEXF
fi
echo 1>&2
echo "We will now reverse the order." 1>&2
echo 1>&2
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We recommend that you try holding space down." 1>&2
echo 1>&2
if [[ "$RAND" -le 499 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
( ./"$NATORI.alt"; ./"$NATORI" ; ./"$NATORI.alt" ; ./"$NATORI"; \
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
( ./"$NATORI"; ./"$NATORI.alt" ; ./"$NATORI" ; ./"$NATORI.alt"; \
./"$NATORI"; ./"$NATORI.alt" ) | less -rEXF
fi
echo 1>&2
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We now recommend that you try holding enter down." 1>&2
echo 1>&2
if [[ "$RAND" -le 499 ]]; then
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
( ./"$NATORI.alt"; ./"$NATORI" ; ./"$NATORI.alt" ; ./"$NATORI"; \
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
else
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
( ./"$NATORI"; ./"$NATORI.alt" ; ./"$NATORI" ; ./"$NATORI.alt"; \
./"$NATORI"; ./"$NATORI.alt" ) | less -rEXF
fi
echo 1>&2
# Finally, for the try.alt.sh (alt code, southern hemisphere), force
# starting with southern hemisphere.
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We now recommend that you try holding enter down." 1>&2
read -r -n 1 -p "Press any key to alternate between the southern/northern hemisphere Moon: "
echo 1>&2
( ./"$NATORI.alt"; ./"$NATORI" ; ./"$NATORI.alt" ; ./"$NATORI"; \
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
echo 1>&2
}
# show the Moon phase in artistic ways!
moon
+11
View File
@@ -144,6 +144,17 @@ moon()
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
fi
echo 1>&2
# Finally, for the try.sh (original entry, northern hemisphere), force
# starting with northern hemisphere.
echo "Will now use less(1): 'q' = quit, space = next page, enter = next line." 1>&2
echo "We now recommend that you try holding enter down." 1>&2
read -r -n 1 -p "Press any key to alternate between the northern/southern hemisphere Moon: "
echo 1>&2
( ./"$NATORI"; ./"$NATORI.alt" ; ./"$NATORI" ; ./"$NATORI.alt"; \
./"$NATORI"; ./"$NATORI.alt" ) | less -rEXF
echo 1>&2
}
# show the Moon phase in artistic ways!