g | x | w | all
Bytes Lang Time Link
072Haskell + hgl240717T144836ZWheat Wi
165Lexurgy240717T161918Zbigyihsu
060JavaScript Node.js181017T093417Ztsh
060Perl 6181017T103044Znwellnho
688Retina 0.8.2181017T082607ZNeil
032Jelly181016T225107ZJonathan
nanAPL Dyalog181016T234035ZAdalynn

Haskell + hgl, 72 bytes

Uses u and d to indicate tones

f=fcq sA<fmX ao<K
skX"du_|d_.+u"<<fo<<f"d"^.f"u"1<gky(rX".[ャュョ]?")

Attempt This Online!

Explanation

We define f as a function to insert a value at a particular location in a list. We will use this to insert the tone markings.

No regex, 81 bytes

Uses / and , to indicate tones

f=fcq sA<fmX ao<K
fo<<(!)(f"/"1:f","1:f"/"1<<f","<eF2)^.gky(hdS<>?xys"ャュョ")

Attempt This Online!

Explanation

We use the same f function as the last answer.

Reflection

This is very long, I think it could be shorter somehow, but I'm not sure. There are a couple of improvements that already jump out though.

Lexurgy, 442 165 bytes

class F {I,ャ,ュ,ョ,^,v}
element s !@F @F*(0-2)
h:
*=>^/$ @s _
I @s$1 *=>* $1 v/$ _
@s$1 * *=>v $1 ^/$ I+ _
l propagate:
I=>*/_ !@F
then:
v @s$1 => $1 v/$ I []* _

Try it on Lexurgy!

Expects input of the form IK, where I is the unary representation of the kind of pitch accent with each digit being I, and K which is the kana string. So, the input 4 アタラシイ would be IIIIアタラシイ.

Output uses ^v for /\.

Ungolfed Explanation

class K {ア,イ,ウ,エ,オ,カ,キ,ク,ケ,コ,サ,シ,ス,セ,ソ,タ,チ,ツ,テ,ト,ナ,ニ,ヌ,ネ,ノ,ハ,ヒ,フ,ヘ,ホ,マ,ミ,ム,メ,モ,ヤ,ユ,ヨ,ラ,リ,ル,レ,ロ,ワ,ン,ッ,ガ,ギ,グ,ゲ,ゴ,ザ,ジ,ズ,ゼ,ゾ,ダ,ヂ,ヅ,デ,ド,バ,ビ,ブ,ベ,ボ,パ,ピ,プ,ペ,ポ}
class Y {ャ,ュ,ョ}
class p {^,v}
element syl @K @Y? @p? # a mora is a big kana with optional small kana. add ^,v so that it's considered part of the syllable
# `syllable` wasn't used here because it ended up being really hard to implement using syllables, and trying to account for the unary numeral at the front.
# use unary I for counting
# no I for 0, one I for 1, etc.

heibangata:
# 0 = LHH...
* => ^ / $ @syl _

atamadakagata:
# 1 = HLL...
I @syl$1 * => * $1 v / $ _

the-rest-start:
# k>1= L.k*H.L...
# start by placing a rise after the 1st syllable:
@syl$1 * * => v $1 ^ / $ I+ _
# then propagate so that we delete one I each time, and move the L to the right 1 syllable
the-rest-loop propagate:
I => * / _ @K # delete an I
then:
v @syl$1 => $1 v / $ I []* _ # move the v to the right when there is an I to start

JavaScript (Node.js), 60 bytes

n=>s=>s.replace(/.[ャュョ]?/g,s=>i=--n-i?s+1:n?s:s+2,i=0)

Try it online!

Perl 6, 63 60 bytes

-3 bytes thanks to Lynn's suggestion to use other separators than / \

->\n{&{S:g[.<[ャュョ]>?]=$/~7 x!$++*?+^-n~1 x(++$==n>0)}}

Try it online!

Curried function. Uses 7 1 instead of / \.

Explanation

->\n{     # Block taking argument n
  &{      # Return a block
    S:g   # Replace globally
    [.<[ャュョ]>?]  # regex for mora
    =$/            # with match
     ~7            # followed by 7
      x!$++*?+^-n  # if i==1 and n!=1
                   # should be read as (! $++) * (? +^ - n)
                   # +^ is bitwise negation like ~ in C
                   # ? converts to Bool like !! in C
                   # so ?+^-n is like !!~-n or !!(n-1) or n!=1
     ~1            # followed by 1
      x(++$==n>0)  # if i==n and n>0
  }
}

Retina 0.8.2, 68 bytes (UTF-8)

\d+(.[ャュョ]?)
$1/$&$*1\
/1\b

/.
/
+`1(1*.)(.[ャュョ]?)
$2$1

Try it online! Link includes test cases. Explanation:

\d+(.[ャュョ]?)
$1/$&$*1\

Convert the number to unary, wrap it in /\, and insert it after the first mora.

/1\b

If the number was 1, then delete it and the /, leaving the \.

/.
/

Subtract 1 from the number, but in the case of 0, this deletes the \, leaving the /.

+`1(1*.)(.[ャュョ]?)
$2$1

Move the \ one mora to the right for each remaining 1.

Jelly, 32 bytes

O%62ḟ€“579‘œṗ⁸Ḋ⁹‘+Ị$,2¤œṖżCØ.ḟƊ}

A full program accepting a list of characters and a non-negative integer which prints using 0 for / and 1 for \.

Try it online! Or see the test-suite.

How?

O%62ḟ€“579‘œṗ⁸Ḋ⁹‘+Ị$,2¤œṖżCØ.ḟƊ} - Main Link: list of characters S, integer N
O                                - convert to ordinals
 %62                             - modulo by 62
      “579‘                      - code-page indices list = [53,55,57]
                                 -   (representing the three optional characters)
     €                           - for each ordinal:
    ḟ                            -   filter discard if in [53,55,57]
             ⁸                   - chain's left argument, S
           œṗ                    - partition before truthy indices
                                 -   (so before the non optional character positions)
              Ḋ                  - dequeue (remove the leading empty list)
                       œṖ        - partition at indices...
                      ¤          - nilad followed by (links) as a nilad:
               ⁹                 -   chain's right argument, N
                ‘                -   increment
                   $             -   last two links as a monad:
                 +               -     add
                  Ị              -     insignificant? (1 if 1; 0 if 2+)
                    ,2           -   pair with 2
                               } - use right argument, N, for...
                              Ɗ  - last three links as a monad:
                          C      -   compliment = 1-N
                             ḟ   -   filter discard if in...
                           Ø.    -   bits = [0,1]
                                 -     (i.e. if N=0:[0], if N=1:[1], otherwise:[0,1])
                         ż       - zip together
                                 -   e.g. [[["ジュ"],0],[["ウ","イ","チ","ガ","ツ"],1]]
                                 - implicit (smashing) print
                                 -   e.g. ジュ0ウイチガツ1

APL (Dyalog), 45 characters / 51 bytes* / 83 bytes

{S←⍵⊂⍨~⍵∊'ャュョ'⋄S[⍺~0],←'\'⋄S[0~⍨⍺≠1],←'/'⋄∊S}

Try it online!

The second score only applies if the three Katakana characters in the code can be counted as a different encoding than the other portion of the code.