7
Your program is given a string consisting entirely of lowercase letters at STDIN (or closest alternative). The program must then output a truthy or falsey value, depending on whether the input is valid romaji.
Rules:
- It must be possible to divide the entire string into a sequence of kana without any leftover characters.
- Each kana can be a single vowel (
aeiou
) - Each kana can also be a consonant p, g, z, b, d, k, s, t, n, h, m, or r followed by a vowel. For example, ka and te are valid kana, but qa is not.
- The exceptions to the above rule are that zi, di, du, si, ti, and tu are not valid kana.
- The following are also valid kana: n, wa, wo, ya, yu, yo, ji, vu, fu, chi, shi, tsu.
- If a particular consonant is valid before an i (i.e ki, pi), the i can be replaced by a ya, yu, or yo and still be valid (i.e kya, kyu, kyo)
- Exceptions to the above rule are chi and shi, for which the y has to be dropped too (i.e cha, chu, cho, sha, shu, sho)
- It is also valid to double consonants if they are the first character of a kana (kka is valid but chhi is not)
- Shortest answer wins. All regular loopholes are disallowed.
List of all valid kana:
Can have double consonant:
ba, bu, be, bo, bi
ga, gu, ge, go, gi
ha, hu, he, ho, hi
ka, ku, ke, ko, ki
ma, mu, me, mo, mi
na, nu, ne, no, ni
pa, pu, pe, po, pi
ra, ru, re, ro, ri
sa, su, se, so,
za, zu, ze, zo,
da, de, do,
ta, te, to,
wa, wo,
ya, yu, yo,
fu,
vu
ji
Can not have double consonant:
a, i, u, e, o,
tsu,
chi, cha, cho, chu,
shi, sha, sho, shu,
n
Test cases
Pass:
kyoto
watashi
tsunami
bunpu
yappari
Fail:
yi
chhi
zhi
kyi
How do we win? Is this a code golf? – caird coinheringaahing – 2017-05-24T00:09:37.357
2Need test cases. Also could do with a list of all valid kana instead of the rules – Robert Fraser – 2017-05-24T00:11:05.033
1@RobertFraser both is preferred - test cases are not rules – Stephen – 2017-05-24T00:12:18.673
If
pa pi pu pe po
are valid kana, then can't you simply groupp
with the other consonants? – Value Ink – 2017-05-24T00:15:59.960I added all the kana, I think. Please tell me if I missed some. – takra – 2017-05-24T00:20:06.643
@ValueInk good point, that makes it easier to understand – takra – 2017-05-24T00:20:29.103
"If a particular consonant is valid before an i (i.e ki, pi), the i can be replaced by a ya, yu, or yo and still be valid (i.e kya, kyu, kyo)" The list seems to be missing these for "h", and "p" – Jonathan Allan – 2017-05-24T02:32:38.590
The list is missing all doubled consonant variants. Is
chchi
valid or not (i.e. isch
considered a character)? – Jonathan Allan – 2017-05-24T02:38:16.780I've updated list of valid kana, but
n
needs clarification – Dead Possum – 2017-05-24T14:08:45.1972
n
cannot be doubled. I know enough about the Japanese alphabets to say that. Ifn
was doubled, it would need to have a vowel after, but then it wouldn't ben
. So ifkanna
was a word (just making it up), it'd actually beka n na
. – mbomb007 – 2017-05-24T14:16:40.7371
You know, I wanted to make a solution using
– mbomb007 – 2017-05-24T14:30:48.697unicodedata
, but it'll definitely be longer than a regex solution. Partial program@mbomb007 Does it output vowels twice intended? – Dead Possum – 2017-05-24T14:34:49.287
@DeadPossum This isn't a solution. If I were going to use it, I'd be checking if the list contains something. – mbomb007 – 2017-05-24T14:35:31.650