Japanese kana characters correspond to a single sound in the Japanese language. With the exception of ん (n), every other kana consists of a consonant part and a vowel part. There is a natural ordering to Japanese kana, a sort of "alphabetical order", which is typically arranged in a 10 by 5 table:

   |   a    i    u    e    o
*  |   a    i    u    e    o
k  |  ka   ki   ku   ke   ko
s  |  sa   si   su   se   so
t  |  ta   ti   tu   te   to
n  |  na   ni   nu   ne   no
h  |  ha   hi   hu   he   ho
m  |  ma   mi   mu   me   mo
y  |  ya        yu        yo
r  |  ra   ri   ru   re   ro
w  |  wa                  wo

This ordering is called gojuuon, or "fifty sounds", even though some of the fifty cells in the table are in fact empty.

The challenge

Input will be any of the listed kana above, with the exception for wo. Your program or function should output the next kana along in left-to-right, top-to-bottom reading order, e.g:

Input       Output
a     ->    i
i     ->    u
o     ->    ka
ke    ->    ko
so    ->    ta
ni    ->    nu
ya    ->    yu
yu    ->    yo
wa    ->    wo
wo    ->    (undefined behaviour)

With the exception of an optional single trailing newline, there should be no leading or trailing whitespace in the output.

This is , so the goal is to minimise program size, in bytes.

Additional notes

  • In order to keep things simple, this challenge uses Nihon-shiki romanisation. Hepburn romanisation is more common, but has a few kinks which make things more annoying for golf (e.g. si becomes shi, hu becomes fu).

  • Kana do exist for the empty spots (see Japanese SE), but they were either non-standard or are now obsolete.

  • 4
    \$\begingroup\$ I think it would be much more fun to use the Hepburn exceptions and make wo transform to n which loops to a. \$\endgroup\$
    – Jan
    Commented Jan 7, 2016 at 13:22

16 Answers 16


Retina, 54 53 bytes


Try it online.


Wooo, showing off even more features from today's 0.7.2 release. :) (The release predates this challenge by about 7 hours.)


This is a transliteration which replaces a with i and u with e, but only in matches of y.. The purpose of that is to treat ya and yu like yi and ye, respectively, in order to skip the gaps.


Replace wa with we to skip that gap as well.


Here is the new feature. When rotating sets of characters, the "from" and "to" set in a transliteration are usually almost identical. So now we've got o (without a backslash) to refer to the other set, which allows us to get rid of some duplication. The \o just stands for a literal o in that case. So the two sets expand to:


The extraneous a in the second set is ignored and the vowels are replaced cyclically as expected.


This does the same thing for the consonants, but using o in the first set (just because we can...). h and w need escaping because they are character classes. The expanded sets are:


The .a restricts this operation to syllables that end in a, i.e. those that wrap to the next line of the table.


Finally, we replace a single a with ka, because that case cannot be handled by the previous transliteration.

  • \$\begingroup\$ Doesn't using a version of your language released after the challenge was posted disqualify your entry from competing? (Guess why I asked about this in that other place? ;) \$\endgroup\$
    – Alex
    Commented Jan 8, 2016 at 13:27
  • \$\begingroup\$ @Alex I released that version before this challenge was posted. \$\endgroup\$ Commented Jan 8, 2016 at 13:29
  • \$\begingroup\$ Okay. My apologies. Your edit made it appear otherwise. I just verified your list of releases (probably should've done that before throwing accusations around). \$\endgroup\$
    – Alex
    Commented Jan 8, 2016 at 13:32

GNU sed, 65

Comments not included in score:

:                        # Define unnamed label
y/aiueo/iueoa/           # Rotate vowels
/a/y/kstnhmyr/stnhmyrw/  # If at end of row, rotate consonants
s/^a/ka/                 # If at end of 1st row, prefix a "k"
/[yw][ie]\|wu/b          # If one of the invalid values, jump back to label and redo

Oy, this is beginning to look a lot like @Martin's Retina answer (but longer, of course).


Pyth, 42 40 38 bytes

s.r]z.DrR6*" kstnhmyrw""aiueo"CM"$&./0

This takes the outer product between vowels and consonants, and removes elements at the ords of each number in $&./0. Then it outputs the element after the input.

@J.DrR6*" kstnhmyrw""aiueo"CM"$&./0"hxJz    Implicit: z=input()
       *" kstnhmyrw""aiueo"                 Outer product: [' a',...,' o','ka',...]
    rR6                                     Strip each string—'a'~'o' now single letters
                           CM"$&./0"        Map ord onto the string: [36,38,46,47,48]
  .D                                        Remove elements at those indices.
 J                                          That's the list of kana; assign it to J
                                     xJz    Find the index (x) of z in J,
                                    h       add one,
@J                                          and access J at that index.

Try it here.

  • \$\begingroup\$ Wow, this language is crazy! \$\endgroup\$ Commented Sep 11, 2018 at 10:50

Ruby, 105

'rymhntsk '.chars{|c|a+='*o *e *u *i *a'.tr(?*,c).split}

Commented in test program

f=->n{a=['wo','wa']                     #initialize array to last line of table, begin to build table backwards                                
  'rymhntsk '.chars{|c|                 #for each consonant, 
    a+='*o *e *u *i *a'.tr(?*,c).split  #perform a sustitution to get that line of table in string form,  
  }                                     #then split into array at spaces and append to a
  a[8..10]='yu'                         #substitute 3 elements ye yu yi with 1 element yu
  a[a.index(n)-1]                       #return element before argument (array is backwards.)

puts f[gets.chop]
  • \$\begingroup\$ You can save a few bytes with a=%w{wo wa}. \$\endgroup\$
    – Jordan
    Commented Sep 15, 2016 at 22:45
  • \$\begingroup\$ Also: "rymhntsk ".chars{|c|"oeuia".chars{|d|a<<c+d}}, although I have a sneaking suspicion it could be golfed further. \$\endgroup\$
    – Jordan
    Commented Sep 15, 2016 at 23:02

TXR Lisp, 135 127 124 91 bytes

(ret[(memqual @1(diff(maprod(op trim-str`@1@2`)" kstnhmyrw""aiueo")'#"yi ye wi wu we"))1])


1> (ret[(memqual @1(diff(maprod(op trim-str`@1@2`)" kstnhmyrw""aiueo")'#"yi ye wi wu we"))1])
#<interpreted fun: lambda (#:arg-1-0208 . #:arg-rest-0207)>
2> [*1 "a"]
3> [*1 "o"]
4> [*1 "ki"]
5> [*1 "mu"]
6> [*1 "ya"]
7> [*1 "yo"]
8> [*1 "wa"]

Bash + sed, 83

echo {,k,s,t,n,h,m,y,r,w}{a,i,u,e,o}|sed -E "s/[yw][ie]|wu//g;s/.*\b$1 +//;s/ .*//"
  • Brace expansion to create full table on one line
  • sed to:
    • remove yi, ye, wi, wu and we
    • remove everything up to and including the input entry (but not the next entry)
    • remove everything after the next entry

JavaScript, 145 162 131 118 bytes

x=>(d=" kstnhmyrw".replace(/./g,"$&a$&i$&u$&e$&o").replace(/ |yi|ye|wiwuwe/g,"").match(/[^aiueo]?./g))[d.indexOf(x)+1]

Admit it, you couldn't imagine a more ridiculous solution to solve this problem ;) ok, done this in a more interesting way.


function p(x) {
  return (d=" kstnhmyrw".replace(/./g,"$&a$&i$&u$&e$&o") //build the sequence of kana, regex rulez!
        .replace(/ |yi|ye|wiwuwe/g,"")                   //remove the spaces and excess kana
        .match(/[^aiueo]?./g))[d.indexOf(x)+1]           //split it into array using regex and get the index of input in it


  • \$\begingroup\$ @Sp3000 Oh, that's a pity, you should then mention that these excess (trailing/leading) spaces ain't allowed. \$\endgroup\$
    – nicael
    Commented Jan 6, 2016 at 22:43
  • \$\begingroup\$ @nicael I don't see anything in the spec implying that they are currently allowed. \$\endgroup\$ Commented Jan 6, 2016 at 22:49
  • \$\begingroup\$ @Sp3000 fixed spacing. \$\endgroup\$
    – nicael
    Commented Jan 6, 2016 at 22:53

Japt, 75 70 68 bytes

X=" kstnhmyrw"£"aiueo"®+X w} r" |yi|ye|wiwuwe"P f"[^aiueo]?.")g1+XbU

Try it online!

  • \$\begingroup\$ Pretty nice! I tried to golf this down more, but I could only chop off 3 bytes: X=" kstnhmyrw"£"aiueo"mZ{X+Z} } r" |yi|ye|wiwuwe"P f"[^aiueo]?.")g1+XbU \$\endgroup\$ Commented Jan 7, 2016 at 18:21
  • \$\begingroup\$ @Eth yeah, and also you've got an excess space in } } :) \$\endgroup\$
    – nicael
    Commented Jan 7, 2016 at 18:38
  • \$\begingroup\$ Ohhhh right, I forgot that was automatically added :) \$\endgroup\$ Commented Jan 7, 2016 at 18:44
  • \$\begingroup\$ @Eth look, we can get it two bytes shorter with your magic shortcuts :D \$\endgroup\$
    – nicael
    Commented Jan 7, 2016 at 18:50
  • \$\begingroup\$ Wait, that actually works? Nice, you've outgolfed me ;) \$\endgroup\$ Commented Jan 7, 2016 at 18:51

Haskell, 114 96 bytes

f x=snd(span(/=x)[words[a,b]!!0|a<-" kstnhmyrw",b<-"aiueo"])!!1

[words[a,b]!!0|a<-" kstnhmyrw",b<-"aiueo"] is a list of all kanas, including the "holes". I break up the list into the part before the input kana and from the input kana up to the end. From the 2nd part I pick the second element. The exceptions around the "holes" a caught before by separate cases.

Edit: @xnor came up with the idea of using spanwhich saved 18 bytes.

  • \$\begingroup\$ Would something like (snd$span(/=x)k)!!1 not work for the lookup? \$\endgroup\$
    – xnor
    Commented Jan 7, 2016 at 6:43
  • \$\begingroup\$ @xnor: now that I see it, it's obvious. Thanks so much! \$\endgroup\$
    – nimi
    Commented Jan 7, 2016 at 18:53

Lexurgy, 115 bytes

'=>k/$ _
{',k,s,t,n,h,m,y,r,w} '=>{k,s,t,n,h,m,y,r,w,`} *
{i,e}=>{u,o}/y _


# advance the vowel
# advance the consonant
'=>k/$ _ # o => ka case
{',k,s,t,n,h,m,y,r,w} '=>{k,s,t,n,h,m,y,r,w,`} * # everything else
# force yu yo
{i,e}=>{u,o}/y _
  • \$\begingroup\$ definitely the right tool for the job \$\endgroup\$
    – Razetime
    Commented Jan 21, 2022 at 3:51

Perl 6, 105 bytes

.[.first(@*ARGS[0],:k)+1].say with (" kstnhmyrw".comb X~ <a e i o u>).grep(* !~~/[y|w][i|e]|wu/)».trim

This is as short as I can get it on my first go, I might have another crack at it later but I feel pretty good about this.


JavaScript (ES6), 127 bytes




  // Hardcode "yu", "ya" and "wa"

  // Generate table
  (m=[].concat(...                                   // flatten the array of arrays
    ["",                                             // first consonant is blank
    ..."kstnhmyrw"].map(c=>[..."aiueo"].map(v=>c+v)) // combine each consonant and vowel
  ))[m.indexOf(s)+1]                                 // return the next sound


var solution = s=>s>"yt"?"yo":s=="ya"?"yu":s=="wa"?"wo":(m=[].concat(...["",..."kstnhmyrw"].map(c=>[..."aiueo"].map(v=>c+v))),m[m.indexOf(s)+1])
<input type="text" id="input" value="mo" />
<button onclick="result.textContent=solution(input.value)">Go</button>
<pre id="result"></pre>


Perl 6, 96 bytes

{my @a=(" kstnhmyrw".comb X~ <a i u e o>).grep({!/[y|w][e|i]|wu/})>>.trim;@a[[email protected]($_,:k)]}

Python 2, 107 bytes

L=[(x+y).lstrip()for x in' kstnhmyrw'for y in'aiueo'if x+y not in'yiyewiwuwe']
print L[L.index(input())+1]

Expects input enclosed in quotes, 'he' for example


Racket 151 bytes

(second(member s '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na
ni nu ne no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo)))


(define (f s)
   (member s
           '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na ni nu ne
               no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo))))


(f 'a)
(f 'i)
(f 'o)
(f 'ke)
(f 'so)
(f 'ni)
(f 'ya)
(f 'yu)
(f 'wa)



There is an error message if 'wo is sent.


C, 138 135 bytes




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.