#!/bin/bash #set -x declare -i n=10 declare -i i=0 declare -i w=0 start=$(date +%s) while (( ${#answers[@]} < $n )); do x=$(( RANDOM % (n+1) )) correct=$(( x * x * x )) if [[ -z ${answers[$x]} ]]; then while [[ ${answers[$x]} != $correct ]]; do echo "$i: $x * $x * $x = " read y answers[$x]=$y if [[ $y == $correct ]]; then echo Correct else echo Wrong ((w++)) wrong[$w]=$x fi done ((i++)) fi done end=$(date +%s) #echo ${answers[@]} if (( w > 0 )); then echo "You gave $w wrong answers." echo "These are the cubes you got wrong ${wrong[@]}" else echo "Great work! You got them all right!" fi ((secs=end-start)) printf 'You took: %02dh:%02dm:%02fs\n' \ $(echo -e "$secs.0/3600\n$secs.0%3600/60\n$secs.0%60"| bc)