Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
function guess {
|
||||
[[ -n $BASH_VERSION ]] && shopt -s extglob
|
||||
[[ -n $ZSH_VERSION ]] && set -o KSH_GLOB
|
||||
local -i max=${1:-100}
|
||||
local -i number=RANDOM%max+1
|
||||
local -i guesses=0
|
||||
|
||||
local guess
|
||||
while true; do
|
||||
echo -n "Guess my number! (range 1 - $max): "
|
||||
read guess
|
||||
if [[ "$guess" != +([0-9]) ]] || (( guess < 1 || guess > max )); then
|
||||
echo "Guess must be a number between 1 and $max."
|
||||
continue
|
||||
fi
|
||||
let guesses+=1
|
||||
if (( guess < number )); then
|
||||
echo "Too low!"
|
||||
elif (( guess == number )); then
|
||||
echo "You got it in $guesses guesses!"
|
||||
break
|
||||
else
|
||||
echo "Too high!"
|
||||
fi
|
||||
done
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue