Created
September 9, 2012 16:19
-
-
Save mjf/3685390 to your computer and use it in GitHub Desktop.
Practice Chinese Numbers from 0 to 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Practice Chinese Numbers from 0 to 10 (in Pinyin) | |
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/> | |
# Released under the terms of The MIT License | |
# | |
# Note: requires UTF-8 ANSI-compatible terminal (XTerm) | |
hanzi[0]='零' | |
hanzi[1]='一' | |
hanzi[2]='二' | |
hanzi[3]='三' | |
hanzi[4]='四' | |
hanzi[5]='五' | |
hanzi[6]='六' | |
hanzi[7]='七' | |
hanzi[8]='八' | |
hanzi[9]='九' | |
hanzi[10]='十' | |
pinyin[0]='líng' | |
pinyin[1]='yī' | |
pinyin[2]='èr' | |
pinyin[3]='sān' | |
pinyin[4]='sì' | |
pinyin[5]='wǔ' | |
pinyin[6]='liù' | |
pinyin[7]='qī' | |
pinyin[8]='bā' | |
pinyin[9]='jiǔ' | |
pinyin[10]='shí' | |
apinyin[0]='ling2' | |
apinyin[1]='yi1' | |
apinyin[2]='er4' | |
apinyin[3]='san1' | |
apinyin[4]='si4' | |
apinyin[5]='wu3' | |
apinyin[6]='liu4' | |
apinyin[7]='qi1' | |
apinyin[8]='ba1' | |
apinyin[9]='jiu3' | |
apinyin[10]='shi2' | |
seqn() | |
{ | |
case $1 in | |
1) | |
printf -- '%dst\n' $1 | |
;; | |
2) | |
printf -- '%dnd\n' $1 | |
;; | |
3) | |
printf -- '%drd\n' $1 | |
;; | |
4) | |
printf -- '%dth\n' $1 | |
;; | |
0|5) | |
printf -- 'none\n' | |
;; | |
esac | |
} | |
l=-1 | |
f=-1 | |
while : | |
do | |
r=0 | |
while : | |
do | |
t=$((RANDOM % 4 + 1)) | |
if [ $f -gt -1 ] | |
then | |
if [ $t -eq $f ] | |
then | |
continue | |
fi | |
fi | |
f=$t | |
break | |
done | |
while : | |
do | |
n=$((RANDOM % 11)) | |
if [ $l -gt -1 ] | |
then | |
if [ $n -eq $l ] | |
then | |
continue | |
fi | |
fi | |
l=$n | |
break | |
done | |
case $t in | |
1) | |
printf -- 'Type number for ' | |
printf -- '\033[1m% 2d\033[0m (in Pīnyīn)... ' $n | |
read answer | |
e=$? | |
if [ ${answer:-none} != ${apinyin[n]} ] | |
then | |
r=1 | |
fi | |
;; | |
2) | |
printf -- 'Type number for ' | |
printf -- '\033[1m%s\033[0m (in Pīnyīn)... ' ${hanzi[n]} | |
read answer | |
e=$? | |
if [ ${answer:-none} != ${apinyin[n]} ] | |
then | |
r=1 | |
fi | |
;; | |
3) | |
printf -- 'Type number for ' | |
printf -- '\033[1m%s\033[0m ... ' ${hanzi[n]} | |
read answer | |
e=$? | |
if [ ${answer:-none} != $n ] | |
then | |
r=1 | |
fi | |
;; | |
4) | |
printf -- 'Type number for ' | |
printf -- '\033[1m%s\033[0m ... ' ${pinyin[n]} | |
read answer | |
e=$? | |
if [ ${answer:-none} != $n ] | |
then | |
r=1 | |
fi | |
;; | |
esac | |
if [ $e -ne 0 ] | |
then | |
printf -- '\n' | |
fi | |
printf -- '\t\033[1m%d\033[0m' $n | |
printf -- '\t\033[1m%s\033[0m' ${hanzi[n]} | |
printf -- '\t\033[1m%s\033[0m' ${pinyin[n]} | |
printf -- '\t(%s tone)\n' ` | |
a=${apinyin[n]} | |
seqn ${a:$((${#a}-1))} | |
` | |
if [ ${answer:-none} = q -o ${answer:-none} = quit ] | |
then | |
break | |
fi | |
case ${answer:-none} in | |
none) | |
: | |
;; | |
*) | |
if [ $r -ne 0 ] | |
then | |
printf -- 'Wrong answer, sorry.\n' | |
fi | |
;; | |
esac | |
printf -- '\n' | |
done | |
printf -- '\nGood bye (再见).\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment