The flick input method is a way of inputting Japanese kana on a modern smartphone. It is arranged in a 12-key layout, with the following labels:
あかさ
たなは
まやら
小わ、
When a key is tapped, it produces its respective kana. However, when the key is flicked in one of the four cardinal directions (up, down, left, right) it produces the kana with the respective vowel:
u
iae
o
where the center vowel is the key, just tapped and not flicked.
So, when the か
key is swiped up, it will produce the く
kana.
A special key is the 小
key. By default, just tapping on the 小
key will cycle the previous kana between it's "small" and "large" forms.
Swiping down-left will apply a dakuten, and down-right a handakuten, if it can be applied to the kana.
For this challenge, the 小
key will have the following flick mapping:
小
゛小゜
゛ <-- this is a dakuten
Kana with dakuten, handakuten, and small forms are in the table below. If the kana does not have a small form when 小
is pressed, it is a NOP. Similarly, if a kana does not have a dakuten or handakuten form when one is applied, it is also a NOP.
Some keys have either a special layout and punctuation characters assigned to them:
Image source: Wikimedia Commons
Note here that the や
and わ
keys have punctuation assigned:
ゆ
(や) <-- unicode FF08, FF09
よ
ん
をわー <-- unicode 30FC
〜 <-- unicode 301C
You will need to handle punctuation, but only on や
and わ
. This challenge will not be using the 、
key.
Hiragana
Hiragana is Japanese's native syllabic writing system. Most hiragana can be considered as a pair of a consonant and a vowel:
a | i | u | e | o | |
---|---|---|---|---|---|
∅ | あ | い | う | え | お |
k | か | き | く | け | こ |
s | さ | し | す | せ | そ |
t | た | ち | つ | て | と |
n | な | に | ぬ | ね | の |
h | は | ひ | ふ | へ | ほ |
m | ま | み | む | め | も |
y | や | ゆ | よ | ||
r | ら | り | る | れ | ろ |
w | わ | を |
"ん" is special because it is the only hiragana without a vowel.
Some hiragana can have a diacritic applied called a "dakuten" or "handakuten" that either voices the consonant (e.g. "k" to "g") or "half-voices" the consonant (only for h-series kana, from "h" to "p"). Some kana also have a small form (applies to vowels, y-series kana, and つ).
Kana | Dakuten | Handakuten | Small |
---|---|---|---|
あいうえお | ぁぃぅぇぉ | ||
かきくけこ | がぎぐげご | ||
さしすせそ | ざじずぜぞ | ||
たちつてと | だぢづでど | っ | |
はひふへほ | ばびぶべぼ | ぱぴぷぺぽ | |
やゆよ | ゃゅょ |
Input
Input is a string of hiragana using any reasonable input format: a string, a list/array of characters, a sequence of raw Unicode bytes, etc.
Output
Output is a sequence of inputs for the 12-key flick input method. You may use any reasonable output format. However, each input in the sequence must be at least 2 distinguishable parts, and must encode at minimum the following:
- Which key is tapped, and
- Which direction it is swiped, if at all.
You must specify what encoding you use for your output. (The two-part output is to prevent mapping kana to a single value one-to-one.)
Test Cases
For these test cases, output will be in the format of space-separated KD
, where K
is the kana's consonant (or "a" if it is あ
), and D
is one of 58426
(directions on a numpad, 5 for no swipe). The 小
key will be represented as x
.
かな --> k5 n5
ありがとう --> a5 r4 k5 x4 t2 a8
ありがとうございます --> a5 r4 k5 x4 t2 a8 k2 x4 s5 x4 a4 m5 s8
だがことわる --> t5 x4 k5 x4 k2 t2 w5 r8
おまえはもうしんでいる --> a2 m5 a6 h5 m2 a8 s4 w8 t6 x4 a4 r8
かかります --> k5 k5 r4 m5 s8
あ --> a5
た --> t5
っ --> t8 x5
ぬ --> n8
ぎゅうにゅ --> k4 x4 y8 x5 a8 n4 y8 x5
やつた --> y5 t8 t5
やづた --> y5 t8 x4 t5
やった --> y5 t8 x5 t5
は --> h5
ば --> h5 x4
ぱ --> h5 x6
(わらい) --> y4 w5 r5 a4 y6
どじゃあぁーん〜 --> t2 x4 s4 x4 y5 x5 a5 a5 x5 w6 w8 w2
を --> w2
This is a related inverse of this post for keitai to kana.