Your challenge is to turn a Japanese word and a dictionary pitch accent number into a new string where the rises and falls in pitch are marked: e.g. (2, ウシロ) →
ウ/シ\ロ
.To help you out with this, I'll explain a little about Japanese phonology.
Background: on moras
For the purpose of this challenge, we will write Japanese words in katakana, the simplest Japanese syllabary. A word consists of one or more moras, each of which consists of
one of:
アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワンッガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポ
optionally followed by one of:
ャュョ
For example, シャッキン consists of 4 moras: シャ, ッ, キ, ン.
※ The three optional characters are small versions of katakana ヤユヨ
(ya yu yo).
For example, キャ is ki + small ya, pronounced kya (1 mora), whereas キヤ is kiya (2 moras).
Background: pitch accents
Japanese words are described by a certain contour of high and low pitches. For example, ハナス (hanasu, speak) is pronounced
ナ
/ \
ハ ス–···
meaning the pitch goes up after ハ ha, then falls after ナ na, and stays low after ス su.
(That is to say: Unaccented grammar particles after su will be low again).
We might describe this contour as “low-high-low-(low…)”, or LHL(L)
for short.
In a dictionary, the pitch of this word would be marked as 2, because the pitch falls after the second mora. There are a few possible pitch patterns that occur in Tōkyō dialect Japanese, and they are all given a number:
0, which represents
LHHH…HH(H)
. This is heibangata, monotone form.イ–バ–ン–··· ··· / or / ヘ ナ
1, which represents
HLLL…LL(H)
. This is atamadakagata, “head-high” form.イ キ \ or \ ノ–チ–··· ···
n ≥ 2, which represents
LHHH…
(length n) followed by a drop toL…L(L)
.
For example, センチメエトル has pitch accent number 4:ン–チ–メ / \ セ エ–ト–ル–···
Such a word must have ≥ n moras, of course.
※ Note the difference between ハシ [0] and ハシ [2]:
シ–··· シ
/ vs / \
ハ ハ ···
You can hear the different pitch accent numbers demonstrated here ♪.
The challenge
Given an integer n ≥ 0 (a pitch accent number as above) and a valid word of at least n moras, insert /
and \
into it at points where those symbols would occur in the diagrams above; i.e. at points in the word where the pitch rises or falls.
The output for (2, ハナス) would be:
ハ/ナ\ス
And the output for (0, ヘイバン) would be:
ヘ/イバン
Remember: you must correctly handle sequences like キョ or チャ as a single mora.
The output for (1, キョウ) is キョ\ウ
, not キ\ョウ
.
Instead of
/
and\
, you may pick any other pair of distinct, non-katakana Unicode symbols.
This is code-golf: the objective is to write the shortest solution, measured in bytes.
Test cases
One per line, in the format n word → expected_output
:
0 ナ → ナ/
0 コドモ → コ/ドモ
0 ワタシ → ワ/タシ
0 ガッコウ → ガ/ッコウ
1 キ → キ\
1 キヤ → キ\ヤ
1 キャ → キャ\
1 ジショ → ジ\ショ
1 チュウゴク → チュ\ウゴク
1 ナニ → ナ\ニ
1 シュイ → シュ\イ
1 キョウ → キョ\ウ
1 キャンバス → キャ\ンバス
2 キヨカ → キ/ヨ\カ
2 キョカ → キョ/カ\
2 ココロ → コ/コ\ロ
2 ジテンシャ → ジ/テ\ンシャ
3 センセイ → セ/ンセ\イ
3 タクサン → タ/クサ\ン
4 アタラシイ → ア/タラシ\イ
4 オトウト → オ/トウト\
6 ジュウイチガツ → ジュ/ウイチガツ\
Generated by this reference solution.