From 89c5171c26514f051a5427e7b3b68561a6231694 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 23 Dec 2023 06:13:24 -0800 Subject: [PATCH] Add try.sh to 1985/august The script has fun with reversing bits too through rev(1) (if installed). The script calls primes.sh even if primes(6) is not installed as that script will check that it's installed and will tell one where to get it if it's not. It only uses the default value, however, so primes.sh is still shown in the README.md file. --- 1985/august/README.md | 6 +++++- 1985/august/primes.sh | 7 +++++-- 1985/august/try.sh | 37 +++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 4 ++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100755 1985/august/try.sh diff --git a/1985/august/README.md b/1985/august/README.md index 84e6dbac2..6cde65b9e 100644 --- a/1985/august/README.md +++ b/1985/august/README.md @@ -15,7 +15,7 @@ make all ### Try: ```sh -./august | head -n 10 +./try.sh ``` If you have the `primes(6)` tool (sometimes part of [BSD @@ -27,6 +27,10 @@ what of the output in the first `N` (say `15` or `25`) lines are primes: ./primes.sh 25 ``` +Note that `try.sh` will run this script anyway, telling you where to get +`primes(6)` if you don't have it installed, but it will only run with the +default value of 15, rather than trying several different values. + ## Judges' remarks: diff --git a/1985/august/primes.sh b/1985/august/primes.sh index a7743ea07..e64d220c4 100755 --- a/1985/august/primes.sh +++ b/1985/august/primes.sh @@ -18,8 +18,11 @@ if [[ -n "$PRIMES" ]]; then while read -r n; do primes "$n" $((n + 1)); done < <((./august | head -n "$COUNT" )) else echo "primes not installed" 1>&2 + echo 1>&2 echo "See the following GitHub repo:" 1>&2 - echo "" 1>&2 - echo " https://github.com/vattam/BSDGames" + echo 1>&2 + echo " https://github.com/vattam/BSDGames" 1>&2 + echo 1>&2 + echo "and after installing try again." exit 1 fi diff --git a/1985/august/try.sh b/1985/august/try.sh new file mode 100755 index 000000000..6ad209e2c --- /dev/null +++ b/1985/august/try.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1985/august +# + +# 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 + +REV="$(type -P rev)" +PRIMES=$(type -P primes) + +read -r -n 1 -p "Press any key to run: ./august | head -n 11: " +echo 1>&2 +./august | head -n 11 + +if [[ -n "$REV" ]]; then + echo 1>&2 + read -r -n 1 -p "Press any key to reverse bits: " + echo 1>&2 + ./august | head -n 11 | "$REV" +fi + +# run primes.sh too +echo 1>&2 +read -r -n 1 -p "Press any key to run: ./primes.sh: " +echo 1>&2 +./primes.sh +exit 0 diff --git a/thanks-for-help.md b/thanks-for-help.md index dd106b159..dfcfa73eb 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -191,6 +191,10 @@ either the default or user specified. The inspiration was the previous 'try' command he gave to have fun with finding primes that might seem unusual in a way. +Cody also added the [try.sh](/1985/august/try.sh) script (which calls +`primes.sh` whether `primes(6)` is installed or not but it only does it once +with the default value). + ## [1985/lycklama](/1985/lycklama/lycklama.c) ([README.md](/1985/lycklama/README.md]))