From bf98cc9052ef195e033d9f1072f1288733191157 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:32:17 -0800 Subject: [PATCH] Improve 2012/konno/try.sh Now randomly selects 10 numbers (in range $((RANDOM % 101))). Also allows one to pass in numbers (or if they wish to they can pass in non-numbers) to pass to the program. The script has new fun numbers. Removed that the valid range is from 0 - 255 as numbers bigger than 255 not only work but some show some fun output (a number of which are used in the script now). --- 2012/konno/README.md | 8 +++++-- 2012/konno/try.sh | 54 ++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/2012/konno/README.md b/2012/konno/README.md index c4e7916c3..8362bc69e 100644 --- a/2012/konno/README.md +++ b/2012/konno/README.md @@ -14,15 +14,19 @@ code](#alternate-code) below. ./konno N ``` -NOTE: N is an integer from 0 to 255. - ## Try: ```sh ./try.sh + +# you can also specify numbers to try before the random and preselected ones: +./try.sh 111 222 333 444 555 666 777 888 999 ``` +Try running [try.sh](try.sh) a number of times as the first part randomly +selects ten numbers to try. + ## Alternate code: diff --git a/2012/konno/try.sh b/2012/konno/try.sh index 4ded663b1..c60835e21 100755 --- a/2012/konno/try.sh +++ b/2012/konno/try.sh @@ -15,47 +15,71 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -echo "$ ./konno 30" 1>&2 +# let user specify args to run on program too +while [[ "$#" -ge 1 ]]; do + read -r -n 1 -p "Press any key to run: ./konno $1: " + echo 1>&2 + ./konno "$1" + echo 1>&2 + shift 1 +done + +# use ten random values (in range $((RANDOM % 101))) +i=0 +# we do it this way to prevent the annoying shellcheck warning that 'i' appears +# to be unused (as it would be if 'for i in {0..9}; do .. done'). +while [[ "$i" -lt 10 ]]; do + NUM="$((RANDOM % 101))" + read -r -n 1 -p "Press any key to run: ./konno $NUM: " + echo 1>&2 + ./konno "$NUM" + echo 1>&2 + ((i++)) +done + + +# finally use some preselected values +read -r -n 1 -p "Press any key to run: ./konno 30: " +echo 1>&2 ./konno 30 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 90: " echo 1>&2 -echo "$ ./konno 90" 1>&2 ./konno 90 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 102: " echo 1>&2 -echo "$ ./konno 102" 1>&2 ./konno 102 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 109: " echo 1>&2 -echo "$ ./konno 109" 1>&2 ./konno 109 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 165: " echo 1>&2 -echo "$ ./konno 165" 1>&2 ./konno 165 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 42: " echo 1>&2 -echo "$ ./konno 42" 1>&2 ./konno 42 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 37: " echo 1>&2 -echo "$ ./konno 37" 1>&2 ./konno 37 echo 1>&2 -read -r -n 1 -p "Press any key to continue: " +read -r -n 1 -p "Press any key to run: ./konno 255: " echo 1>&2 -echo "$ ./konno 255" 1>&2 ./konno 255 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./konno 10000: " +echo 1>&2 +./konno 10000 +echo 1>&2