Skip to content

Instantly share code, notes, and snippets.

@tomaes
Last active June 1, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaes/cc5d3e4de6a13cdbea0cbd6bc205a051 to your computer and use it in GitHub Desktop.
Save tomaes/cc5d3e4de6a13cdbea0cbd6bc205a051 to your computer and use it in GitHub Desktop.
Shell script test mini game...
#!/bin/sh
clear
printf "spot the (missing) digit\n"
# rnd(0..9)
r=$(($RANDOM%10))
# unix EPOCH time in seconds
t=$(($(date +%s)))
for i in {0..9}
do
if [ "$i" -ne "$r" ]; then
printf $i
fi
done
# read an int from keyboard
printf "\n?"
declare -i a
read a
printf "\n"
if [ "$a" -eq "$r" ]; then
echo "YES"
else
echo "NO"
fi
printf "TIME:%is\n" $(($(($(date +%s)))-$t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment