langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -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
}