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:
1 parent
e0cde4d7d7
commit
5e25056532
4 files changed
+194
-2
No files matched your search
@@ -22,6 +22,9 @@ version](#alternate-code) below.
|
|||||||
./try.sh
|
./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
|
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~
|
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
|
./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
|
What happens if you run it in the northern hemisphere? Are there any
|
||||||
differences?
|
differences?
|
||||||
|
|
||||||
@@ -54,6 +60,15 @@ Can you identify any Moon phases that result in the same output of both
|
|||||||
versions? Or are there any?
|
versions? Or are there any?
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./try.alt.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Like with [try.sh](try.sh), try using this multiple times.
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
Here is a nice compact program that changes with the phase of the Moon.
|
Here is a nice compact program that changes with the phase of the Moon.
|
||||||
|
|||||||
Executable
+162
@@ -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
|
||||||
@@ -144,6 +144,17 @@ moon()
|
|||||||
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
|
./"$NATORI.alt"; ./"$NATORI" ) | less -rEXF
|
||||||
fi
|
fi
|
||||||
echo 1>&2
|
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!
|
# show the Moon phase in artistic ways!
|
||||||
|
|||||||
+6
-2
@@ -2534,8 +2534,12 @@ segfault when run or not compile at all (gcc and clang respectively).
|
|||||||
|
|
||||||
Cody also provided alternate code that supports the southern hemisphere.
|
Cody also provided alternate code that supports the southern hemisphere.
|
||||||
|
|
||||||
Cody also provided the [try.sh](/2000/natori/try.sh) script that shows the Moon
|
Cody also provided the [try.sh](/2000/natori/try.sh) and
|
||||||
phase in artistic ways.
|
[try.alt.sh](/2000/natori/try.alt.sh) scripts that show the Moon phase in
|
||||||
|
artistic ways. It is recommended one try both a number of times in a row on
|
||||||
|
different days (that is run `./try.sh` several times in a row a few days apart,
|
||||||
|
until you see all the Moon phases, and run `./try.alt.sh` a few times in a row a
|
||||||
|
few days apart, until you see all the Moon phases).
|
||||||
|
|
||||||
Later on Cody restored the `#include`s in the source code which had been changed
|
Later on Cody restored the `#include`s in the source code which had been changed
|
||||||
by us to make it a one-liner again but this was an error as it was not a
|
by us to make it a one-liner again but this was an error as it was not a
|
||||||
|
|||||||
Reference in new issue
Block a user