Skip to content

Instantly share code, notes, and snippets.

@AJNOURI
Created August 15, 2017 16:53
Show Gist options
  • Save AJNOURI/6346784606631252186c8c37f95ae126 to your computer and use it in GitHub Desktop.
Save AJNOURI/6346784606631252186c8c37f95ae126 to your computer and use it in GitHub Desktop.
Bash script for mental math exercices.
#!/bin/bash
TOTAL=0
HTOTAL=0
function generator(){
# $1: modulus
# $2: addrank
# $3: multrank
MOD=$1
MULTRANK=$2
NBR=0
until (( NBR != 0 ))
do
NBR=$(( ( RANDOM % $MOD)))
done
TOTAL=$NBR
ROUNDED=$(( NBR * MULTRANK ))
#echo $TOTAL
}
#generator 10 100
#echo $TOTAL
#generator 100 100
#echo $TOTAL
#generator 1000 100
#echo $TOTAL
#generator 10 100
#echo $ROUNDED
function question(){
# $1: lle niveau
NIVEAU=$1
LEVEL=$2
generator $NIVEAU 100
clear
echo "Trouver le complementaire de $TOTAL jusqu'a $LEVEL"
}
#question 10 20
#question 100 100
#question 1000 1000
function exercice(){
i=0
TARRAY=()
while true
do
function check(){
if [[ $rep != $rez ]]; then
echo "Oops!! Verifiez votre reponse: le resultat est: $rez"
else
echo "(GOOD!) t:$duration"
fi
read -p "Continuer [Entrer]"
}
question $1 $2
SECONDS=0
read -p '==> ' rep
duration=$SECONDS
TARRAY[i]=$duration
((i++))
rez=$(( $2 - $TOTAL ))
case $rep in
[Qq]* ) echo ${TARRAY[*]}; read -p "Continuer [Entrer]"; break;;
* ) check;;
esac
done
}
while true; do
clear
echo "### Choisissez le niveau 1,2 ou 3 "
read -p 'Votre choix : ' LEVEL
case $LEVEL in
[1]* ) exercice 10 20;;
[2]* ) exercice 100 100;;
[3]* ) exercice 1000 1000;;
[Qq]* ) exit;;
* ) echo "SVP, entrez un des chiffres. ";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment