6
\$\begingroup\$

Overview

As most of y'all who visit chat know, I am Russian by ethnicity[citation not needed]. Recently, I switched from a keyboard that maps the letters 1-to-1 (mnemonic) to Windows' default mnemonic keyboard. Here are the letter mappings:

"`" -> "ъ"
"q" -> "я"
"w" -> "ш"
"e" -> "е"
"r" -> "р"
"t" -> "т"
"u" -> "у"
"i" -> "и"
"o" -> "о"
"p" -> "п"
"a" -> "а"
"d" -> "д"
"f" -> "ф"
"g" -> "г"
"h" -> "х"
"k" -> "к"
"l" -> "л"
"'" -> "ь"
"z" -> "з"
"x" -> "ж"
"v" -> "в"
"b" -> "б"
"n" -> "н"
"m" -> "м"

You may have notcied that s, c, y, and j are missing. This keyboard, unlike the first one I used, has several combining keys (the aforementioned ones) These keys, while also having their own letters mapped to them, can be combined with other keys in sequence to write even more letters. The combinations for those keys are as follows:

"sc" -> "щ"
"ch" -> "ч"
"ya" -> "я"
"ye" -> "э"
"yo" -> "ё"
"yu" -> "ю"
"ja" -> "я"
"je" -> "э"
"jo" -> "ё"
"ju" -> "ю"

Note that there are 3 ways to write я: q, ya, and ja.

To type the single letters mapped to them, either press that key and then press space, or type an unrecognised key combination. Here are the single letter mappings for those keys:

"s" -> "с"
"c" -> "ц"
"y" -> "ы"
"j" -> "й"

For example, if I type in c (note the space), it will give me ц, while typing in cy gives me цы. Typing in yosc is ёщ, and yq is ыя.

The task

Your input will be given as all lowercase Russian + ASCII space, and you task is to convert that to a sequence of letters in the US keyboard I'd have to type.

Testcases

"один" (one) -> "odin"
"стапятидесятитрёхтысячный" (one hundered fifty three thousandth) ->  "stapqtidesqtitryohtysqchnyj" or "stapyatidesyatitryohtysjachnyj" or any variation on the typing of "я" or "ё" 
"код гольф" (code golf) -> "kod gol'f"
"иван рубит дрова вова топит печь" (Ivan is splitting wood, Vova is stoking the stove; a common mnemonic for the six noun cases) -> "ivan rubit drova vova topit pech'"
"разъяренный чтец эгоистично бьёт пятью жердями шустрого фехтовальщика" (An enraged narrator selfishly beats with five poles a nimble fencer; a sentence that uses all 33 Russian letters) -> "raz`yarennyj chtec  jegoistichno b'yot pqt'yu xerdyami wustrogo fehtoval'scika" (note the double space after "chtec". I used a mixture of "q" and "ya" for "я" here)

Scoring

As this is , shortest answer in bytes wins.

\$\endgroup\$
7
  • \$\begingroup\$ Snadbox \$\endgroup\$
    – Seggan
    Commented Feb 24, 2023 at 22:25
  • \$\begingroup\$ Don't you need a double space before chtec as well, because the j is a dead key and consumes the first space to become й? Also, are there two ways to write э? \$\endgroup\$
    – Neil
    Commented Feb 24, 2023 at 23:06
  • \$\begingroup\$ @Neil no, because y is a dead key as well. Since yj is unrecognized, it becomes ый. Yes there are two ways to write э and ё, and three to write я. You may use any of them. \$\endgroup\$
    – Seggan
    Commented Feb 24, 2023 at 23:10
  • \$\begingroup\$ сч has to be s ch right? \$\endgroup\$
    – Neil
    Commented Feb 26, 2023 at 0:28
  • \$\begingroup\$ @Neil yep. (ignore this in parens i need more chars) \$\endgroup\$
    – Seggan
    Commented Feb 26, 2023 at 2:42

3 Answers 3

5
\$\begingroup\$

JavaScript (ES6), 106 bytes

s=>s.replace(/\S/g,c=>"rs tufhc chwsc`y 'yeyuq_yoabvgdexzij klmnop".match(/[scyj]?./g)[c.charCodeAt()%34])

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ @EzioMercer that output is one of many possibilities. As s is a combining key, you need an invalid key or a space after it to type с \$\endgroup\$
    – Seggan
    Commented Feb 25, 2023 at 19:41
5
\$\begingroup\$

Retina 0.8.2, 159 bytes

щ
sc
ч
ch
ё
yo
ю
yu
э
je
ю
ju
T`сцыы`scyj`с[^ scyjц]|ц[^ scyjх]|[йы][^ scyjаеоу]
[сцыы]
$& 
T`а-цшъ-ья`abvg\dexzi-pr-uf\hc\w\`y'q

Try it online! Link includes test cases. Explanation:

щ
sc
ч
ch
ё
yo
ю
yu
э
je
ю
ju

Translate the digraphs.

T`сцыы`scyj`с[^ scyjц]|ц[^ scyjх]|[йы][^ scyjаеоу]

Transliterate any unrecognised pairs starting with s, c, y or j.

[сцыы]
$& 

Insert spaces after any other letter that maps to s, c, y or j.

T`а-цшъ-ья`abvg\dexzi-pr-uf\hc\w\`y'q

Transliterate the rest of the Russian letters.

\$\endgroup\$
2
\$\begingroup\$

Python, 125 bytes

lambda s:re.sub('\S',lambda c:re.findall("[scyj]?.","rs tufhc chwsc`y 'yeyuq_yoabvgdexzij klmnop")[ord(c[0])%34],s)
import re

Attempt This Online!

Port of Arnauld's JS answer.

\$\endgroup\$
0

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.