#!/bin/ash
. /etc/color
r=`random`
C=`expr $r % 6`

case $C in
0) S="9 5 6 3 2 4 8 7 1" ;;
1) S="8 6 5 7 4 2 9 1 3" ;;
2) S="7 2 8 1 9 3 5 6 4" ;;
3) S="1 6 2 4 8 3 9 7 5" ;;
4) S="3 8 7 9 1 5 4 2 6" ;; 
*) S="5 8 1 6 4 2 3 9 7" ;;
esac

M=1 

doinvert()
{
N="$1" 
set -- $S
case $N in
2) S="$2 $1 $3 $4 $5 $6 $7 $8 $9" ;;
3) S="$3 $2 $1 $4 $5 $6 $7 $8 $9" ;;
4) S="$4 $3 $2 $1 $5 $6 $7 $8 $9" ;;
5) S="$5 $4 $3 $2 $1 $6 $7 $8 $9" ;;
6) S="$6 $5 $4 $3 $2 $1 $7 $8 $9" ;;
7) S="$7 $6 $5 $4 $3 $2 $1 $8 $9" ;;
8) S="$8 $7 $6 $5 $4 $3 $2 $1 $9" ;;
9) S="$9 $8 $7 $6 $5 $4 $3 $2 $1" ;; 
esac
}

echo -e $BRIGHT$WHITE
cat << END
Welcome to --> R E V E R S E ----------------- E S R E V E R <--

You must reorder a 9 digit string from 1 to 9. You may pick any of the
individual digits in your string to invert. Then all of the numbers
from the leftmost position, through the one you pick, will be reversed
in their order of presentation. Enter q to quit.
END

echo -e $NORMAL
while [ 1 ] ; do
if [ "$S" = "1 2 3 4 5 6 7 8 9" ] ; then
echo -e "$BLINK YOU DID IT !!$NORMAL$BRIGHT$YELLOWCONGRATULATIONS!$NORMAL"
exit
fi    
echo -e "$GREEN Move #$BRIGHT$M$BLUE -- Your string is $RED --> $CYAN$S$RED <--$NORMAL"
echo -n "How many digits to invert ? "
read C
case $C in
 1|2|3|4|5|6|7|8|9) doinvert $C ; M=`expr $M + 1`;;
 q) exit
esac
done


