Toki pona is a minimalist constructed language, and thus it has minimalist phonotactics (rules describing what sounds make valid words).
Toki Pona has 8 consonant sounds m
, n
, p
, t
, k
, s
, w
, l
and j
and 5 vowel sounds a
, e
, i
, o
, u
. A single basic syllable in toki pona consists of any 1 consonant, any one vowel and optionally an n
. So all of the following are valid:
pi
ko
wa
san
jen
There are four exceptions of sequences that are forbidden they are ji, wu, wo, ti
.
With the basic syllables we can build words. A word is just a string of basic syllables with two special rules:
- When we have an
n
followed by eithern
orm
we drop then
. e.g.jan
+mo
isjamo
notjanmo
- The initial syllable of a word can drop the initial consonant. e.g.
awen
andpawen
are both legal and distinct words. This does allow for words consisting of just a vowel.
Task
Your task is to take a non-empty string consisting of lowercase alphabetic characters (a
through z
) and determine if it makes a valid toki pona word.
When the input is a valid word you should output one value and when it is not you should output another distinct value.
This is code-golf so answers will be scored in bytes with the goal being to minimize the size of the source.
Test cases
Accept:
awen
jan
e
monsuta
kepekin
ike
sinpin
pakala
tamako
jamo
pankulato
pawen
an
nene
nenen
Reject:
bimi
ponas
plani
womo
won
tin
wu
miji
sunmo
anna
sam
kain
op
p
n
n
" - is that both of them in the case when there are two? \$\endgroup\$if-else
,logical processing
or equivalent construct then those languages simply have no concept of truthy and falsey (by definition) and therefore should just use the two distinct values option that should be available to them. Most languages do, so the strict IO just adds extra, boring work. Furthermore competition is intra-language, so the "disadvantage" argument holds no weight. \$\endgroup\$