Skip to content

Instantly share code, notes, and snippets.

@tonytonyjan
Created July 12, 2018 13:28
Show Gist options
  • Save tonytonyjan/0eadb3698bc442686e25b0000f3647ba to your computer and use it in GitHub Desktop.
Save tonytonyjan/0eadb3698bc442686e25b0000f3647ba to your computer and use it in GitHub Desktop.
ja test
#!/usr/bin/env ruby
# frozen-string-literal: true
平仮名 = {
清音: {'あ' => 'a', 'か' => 'ka', 'さ' => 'sa', 'た' => 'ta', 'な' => 'na', 'は' => 'ha', 'ま' => 'ma', 'や' => 'ya', 'ら' => 'ra', 'わ' => 'wa', 'い' => 'i', 'き' => 'ki', 'し' => 'shi', 'ち' => 'chi', 'に' => 'ni', 'ひ' => 'hi', 'み' => 'mi', 'り' => 'ri', 'う' => 'u', 'く' => 'ku', 'す' => 'su', 'つ' => 'tsu', 'ぬ' => 'nu', 'ふ' => 'fu', 'む' => 'mu', 'ゆ' => 'yu', 'る' => 'ru', 'ん' => 'n', 'え' => 'e', 'け' => 'ke', 'せ' => 'se', 'て' => 'te', 'ね' => 'ne', 'へ' => 'he', 'め' => 'me', 'れ' => 're', 'お' => 'o', 'こ' => 'ko', 'そ' => 'so', 'と' => 'to', 'の' => 'no', 'ほ' => 'ho', 'も' => 'mo', 'よ' => 'yo', 'ろ' => 'ro', 'を' => 'o'},
濁音: {'が' => 'ga', 'ざ' => 'za', 'だ' => 'da', 'ば' => 'ba', 'ぱ' => 'pa', 'ぎ' => 'gi', 'じ' => 'ji', 'ぢ' => 'ji', 'び' => 'bi', 'ぴ' => 'pi', 'ぐ' => 'gu', 'ず' => 'zu', 'づ' => 'zu', 'ぶ' => 'bu', 'ぷ' => 'pu', 'げ' => 'ge', 'ぜ' => 'ze', 'で' => 'de', 'べ' => 'be', 'ぺ' => 'pe', 'ご' => 'go', 'ぞ' => 'zo', 'ど' => 'do', 'ぼ' => 'bo', 'ぽ' => 'po'},
拗音: {'きゃ' => 'kya', 'ぎゃ' => 'gya', 'しゃ' => 'sha', 'じゃ' => 'ja', 'ちゃ' => 'cha', 'にゃ' => 'nya', 'ひゃ' => 'hya', 'びゃ' => 'bya', 'ぴゃ' => 'pya', 'みゃ' => 'mya', 'りゃ' => 'rya', 'きゅ' => 'kyu', 'ぎゅ' => 'gyu', 'しゅ' => 'shu', 'じゅ' => 'ju', 'ちゅ' => 'chu', 'にゅ' => 'nyu', 'ひゅ' => 'hyu', 'びゅ' => 'byu', 'ぴゅ' => 'pyu', 'みゅ' => 'myu', 'りゅ' => 'ryu', 'きょ' => 'kyo', 'ぎょ' => 'gyo', 'しょ' => 'sho', 'じょ' => 'jo', 'ちょ' => 'cho', 'にょ' => 'nyo', 'ひょ' => 'hyo', 'びょ' => 'byo', 'ぴょ' => 'pyo', 'みょ' => 'myo', 'りょ' => 'ryo'}
}
片仮名 = {
清音: {'ア' => 'a', 'カ' => 'ka', 'サ' => 'sa', 'タ' => 'ta', 'ナ' => 'na', 'ハ' => 'ha', 'マ' => 'ma', 'ヤ' => 'ya', 'ラ' => 'ra', 'ワ' => 'wa', 'イ' => 'i', 'キ' => 'ki', 'シ' => 'shi', 'チ' => 'chi', 'ニ' => 'ni', 'ヒ' => 'hi', 'ミ' => 'mi', 'リ' => 'ri', 'ウ' => 'u', 'ク' => 'ku', 'ス' => 'su', 'ツ' => 'tsu', 'ヌ' => 'nu', 'フ' => 'fu', 'ム' => 'mu', 'ユ' => 'yu', 'ル' => 'ru', 'ン' => 'n', 'エ' => 'e', 'ケ' => 'ke', 'セ' => 'se', 'テ' => 'te', 'ネ' => 'ne', 'ヘ' => 'he', 'メ' => 'me', 'レ' => 're', 'オ' => 'o', 'コ' => 'ko', 'ソ' => 'so', 'ト' => 'to', 'ノ' => 'no', 'ホ' => 'ho', 'モ' => 'mo', 'ヨ' => 'yo', 'ロ' => 'ro', 'ヲ' => 'o'},
濁音: {'ガ' => 'ga', 'ザ' => 'za', 'ダ' => 'da', 'バ' => 'ba', 'パ' => 'pa', 'ギ' => 'gi', 'ジ' => 'ji', 'ビ' => 'bi', 'ピ' => 'pi', 'グ' => 'gu', 'ズ' => 'zu', 'ブ' => 'bu', 'プ' => 'pu', 'ゲ' => 'ge', 'ゼ' => 'ze', 'デ' => 'de', 'ベ' => 'be', 'ペ' => 'pe', 'ゴ' => 'go', 'ゾ' => 'zo', 'ド' => 'do', 'ボ' => 'bo', 'ポ' => 'po'},
拗音: {'キャ' => 'kya', 'ギャ' => 'gya', 'シャ' => 'sha', 'ジャ' => 'ja', 'チャ' => 'cha', 'ニャ' => 'nya', 'ヒャ' => 'hya', 'ビャ' => 'bya', 'ピャ' => 'pya', 'ミャ' => 'mya', 'リャ' => 'rya', 'キュ' => 'kyu', 'ギュ' => 'gyu', 'シュ' => 'shu', 'ジュ' => 'ju', 'チュ' => 'chu', 'ニュ' => 'nyu', 'ヒュ' => 'hyu', 'ビュ' => 'byu', 'ピュ' => 'pyu', 'ミュ' => 'myu', 'リュ' => 'ryu', 'キョ' => 'kyo', 'ギョ' => 'gyo', 'ショ' => 'sho', 'ジョ' => 'jo', 'チョ' => 'cho', 'ニョ' => 'nyo', 'ヒョ' => 'hyo', 'ビョ' => 'byo', 'ピョ' => 'pyo', 'ミョ' => 'myo', 'リョ' => 'ryo'}
}
mode = ARGV[0]
questions = case mode
when '1' then 平仮名.values.inject({}, :merge)
when '2' then 片仮名.values.inject({}, :merge)
else (平仮名.values + 片仮名.values).inject({}, :merge)
end
wrong_log = []
ary = questions.to_a.shuffle!
while pair = ary.pop
question, answer = pair
print "#{question}: "
if STDIN.gets.chop == answer
puts '%-25s' % ' 正解!'
else
wrong_log << pair
puts '%-25s' % " 不正解!\"#{answer}\" です。"
end
end
correct = questions.size - wrong_log.size
puts "正解率:#{(correct.to_f/(questions.size)*100).round}% (#{correct}/#{questions.size})"
if wrong_log.empty?
puts 'おめでとうございます!全問正解!'
else
puts '間違った:'
puts wrong_log.map{ |question, answer| "#{question} (#{answer})" }.join(', ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment