309 lines
4.8 KiB
Lua
309 lines
4.8 KiB
Lua
-- enum helper
|
|
function Enum(tbl)
|
|
for i = 1, #tbl do
|
|
local v = tbl[i]
|
|
tbl[v] = i
|
|
end
|
|
return tbl
|
|
end
|
|
|
|
COLOR = Enum {
|
|
"Black",
|
|
"Red",
|
|
"Green",
|
|
"Yellow",
|
|
"Blue",
|
|
"Purple",
|
|
"Cyan",
|
|
"LightGray",
|
|
"Gray",
|
|
"HighRed",
|
|
"HighGreen",
|
|
"HighYellow",
|
|
"HighBlue",
|
|
"HighPurple",
|
|
"HighCyan",
|
|
"White"
|
|
}
|
|
|
|
function Colorize(Text,Color)
|
|
if Color ~= nil then
|
|
lColoredText = "\027[38;5;"..tostring(Color-1).."m"..Text
|
|
return lColoredText.."\027[0;m"
|
|
else
|
|
return Text
|
|
end
|
|
end
|
|
|
|
arabic = {
|
|
"1",
|
|
"2",
|
|
"3",
|
|
"4",
|
|
"5",
|
|
"6",
|
|
"7",
|
|
"8",
|
|
"9",
|
|
"0"
|
|
}
|
|
arabic[100] = "00"
|
|
arabic[1000] = "000"
|
|
arabic[10000] = "0000"
|
|
|
|
romaji = {
|
|
"ichi",
|
|
"ni",
|
|
"san",
|
|
"yon",
|
|
"go",
|
|
"roku",
|
|
"nana",
|
|
"hachi",
|
|
"kyuu",
|
|
"juu"
|
|
}
|
|
romaji[100] = "hyaku"
|
|
romaji[1000] = "sen"
|
|
romaji[10000] = "man"
|
|
|
|
kana = {
|
|
"いち",
|
|
"に",
|
|
"さん",
|
|
"よん",
|
|
"ご",
|
|
"ろく",
|
|
"なな",
|
|
"はち",
|
|
"きゅう",
|
|
"じゅう"
|
|
}
|
|
kana[100] = "ひゃく"
|
|
kana[1000] = "せん"
|
|
kana[10000] = "まん"
|
|
|
|
kanji = {
|
|
"一",
|
|
"二",
|
|
"三",
|
|
"四",
|
|
"五",
|
|
"六",
|
|
"七",
|
|
"八",
|
|
"九",
|
|
"十"
|
|
}
|
|
kanji[100] = "百"
|
|
kanji[1000] = "千"
|
|
kanji[10000] = "万"
|
|
|
|
function GetNumber(number,is_arabic)
|
|
|
|
local nMan = math.floor(number/10000)
|
|
local man = ""
|
|
|
|
space = ""
|
|
|
|
if is_arabic then
|
|
if number >= 10000 then
|
|
man = nMan
|
|
end
|
|
else
|
|
if nMan > 1 then
|
|
man = data[nMan]..data[10000]
|
|
elseif nMan == 1 then
|
|
man = space..data[10000]
|
|
end
|
|
end
|
|
|
|
local nSen = math.floor(number/1000)-nMan*10
|
|
local sen = ""
|
|
|
|
space = ""
|
|
|
|
if is_arabic then
|
|
if number >= 1000 then
|
|
sen = nSen
|
|
end
|
|
else
|
|
if nSen > 1 then
|
|
sen = data[nSen]..data[1000]
|
|
elseif nSen == 1 then
|
|
sen = space..data[1000]
|
|
end
|
|
end
|
|
|
|
local nHyaku = math.floor(number/100)-nSen*10-nMan*100
|
|
local hyaku = data[nHyaku] or space..space
|
|
|
|
space = ""
|
|
|
|
if is_arabic then
|
|
if number >= 100 then
|
|
hyaku = nHyaku
|
|
end
|
|
else
|
|
if nHyaku > 1 then
|
|
hyaku = data[nHyaku]..data[100]
|
|
elseif nHyaku == 1 then
|
|
hyaku = space..data[100]
|
|
end
|
|
end
|
|
|
|
local nJuu = math.floor(number/10)-nHyaku*10-nSen*100-nMan*1000
|
|
local juu = data[nJuu] or space..space
|
|
|
|
if is_arabic then
|
|
if number >= 10 then
|
|
juu = nJuu
|
|
end
|
|
else
|
|
if nJuu > 1 then
|
|
juu = data[nJuu]..data[10]
|
|
elseif nJuu == 1 then
|
|
juu = space..data[10]
|
|
end
|
|
end
|
|
|
|
local nSuuji = number-nJuu*10-nHyaku*100-nSen*1000-nMan*10000
|
|
local suuji = data[nSuuji] or space..space
|
|
|
|
|
|
if is_arabic then
|
|
if number >= 0 then
|
|
suuji = nSuuji
|
|
end
|
|
end
|
|
|
|
return man, sen, hyaku, juu, suuji
|
|
end
|
|
|
|
function GetData(mode)
|
|
if mode == 0 then
|
|
data = arabic
|
|
elseif mode == 1 then
|
|
data = romaji
|
|
elseif mode == 2 then
|
|
data = kana
|
|
elseif mode == 3 then
|
|
data = kanji
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-- PROGRAM START
|
|
|
|
print("Specific Mode?")
|
|
print(" (0) Arabic")
|
|
print(" (1) Japanese Romaji")
|
|
print(" (2) Japanese Kana")
|
|
print(" (3) Japanese Kanji")
|
|
|
|
setmode = io.read()
|
|
|
|
print("Tiers of 10 colored? (Y/n)")
|
|
|
|
coloriz = io.read()
|
|
|
|
print("Show equivalences? (Y/n)")
|
|
|
|
skip = io.read()
|
|
|
|
print("Ready?")
|
|
io.read()
|
|
|
|
if string.upper(coloriz) == "N" then
|
|
COLOR = {}
|
|
end
|
|
|
|
-- ENTER ETERNAL LOOP
|
|
while 1 do
|
|
|
|
-- PREPARE
|
|
os.execute("clear")
|
|
modes = 3
|
|
|
|
arabic_script = false
|
|
if setmode == "0" then
|
|
mode = 0
|
|
arabic_script = true
|
|
print("- ARABIC MODE -")
|
|
elseif setmode == "1" then
|
|
mode = 1
|
|
print("- ROMAJI MODE -")
|
|
elseif setmode == "2" then
|
|
mode = 2
|
|
print("- KANA MODE -")
|
|
elseif setmode == "3" then
|
|
mode = 3
|
|
print("- KANJI MODE -")
|
|
else
|
|
mode = math.random(modes)
|
|
print("- RANDOM MODE -")
|
|
end
|
|
GetData(mode)
|
|
number = math.random(99999)
|
|
|
|
-- ASK
|
|
print("")
|
|
e, d, c, b, a = GetNumber(number,arabic_script)
|
|
print(
|
|
Colorize( e, COLOR.HighGreen)..
|
|
Colorize( d, COLOR.HighPurple)..
|
|
Colorize( c, COLOR.HighRed)..
|
|
Colorize( b, COLOR.HighYellow)..
|
|
Colorize( a, COLOR.HighCyan)
|
|
)
|
|
io.read()
|
|
|
|
if string.upper(skip) ~= "N" then
|
|
-- SHOW SOLUTION
|
|
GetData(0)
|
|
e, d, c, b, a = GetNumber(number,true)
|
|
print(
|
|
" Arabic: "..
|
|
Colorize( e, COLOR.HighGreen)..
|
|
Colorize( d, COLOR.HighPurple)..
|
|
Colorize( c, COLOR.HighRed)..
|
|
Colorize( b, COLOR.HighYellow)..
|
|
Colorize( a, COLOR.HighCyan)
|
|
)
|
|
|
|
GetData(1)
|
|
e, d, c, b, a = GetNumber(number,false)
|
|
print(
|
|
" Romaji: "..
|
|
Colorize( e, COLOR.HighGreen)..
|
|
Colorize( d, COLOR.HighPurple)..
|
|
Colorize( c, COLOR.HighRed)..
|
|
Colorize( b, COLOR.HighYellow)..
|
|
Colorize( a, COLOR.HighCyan)
|
|
)
|
|
GetData(2)
|
|
e, d, c, b, a = GetNumber(number,false)
|
|
print(
|
|
" Kana: "..
|
|
Colorize( e, COLOR.HighGreen)..
|
|
Colorize( d, COLOR.HighPurple)..
|
|
Colorize( c, COLOR.HighRed)..
|
|
Colorize( b, COLOR.HighYellow)..
|
|
Colorize( a, COLOR.HighCyan)
|
|
)
|
|
GetData(3)
|
|
e, d, c, b, a = GetNumber(number,false)
|
|
print(
|
|
" Kanji: "..
|
|
Colorize( e, COLOR.HighGreen)..
|
|
Colorize( d, COLOR.HighPurple)..
|
|
Colorize( c, COLOR.HighRed)..
|
|
Colorize( b, COLOR.HighYellow)..
|
|
Colorize( a, COLOR.HighCyan)
|
|
)
|
|
io.read()
|
|
end
|
|
end
|
|
|