21
2
Given the following input:
- An integer
nwheren > 0. - A string
swheresis not empty ands~=[0-9A-Z]+(alpha-numeric capitals only).
Using a standard, simplified QWERTY keyboard (as shown below):
1234567890
QWERTYUIOP
ASDFGHJKL
ZXCVBNM
Perform the following operation:
- Find the original row that each character is in on the keyboard.
- Replace the letter with the correct shifted equivalent for
nbased on its original position + n.- E.G.
s="AB"andn=2:Awould becomeDandBwould becomeM.
- E.G.
- If
keyboard_row[position + n] > keyboard_row.length, wrap back to the start.- E.G.
s="0P"andn=2:0would become2andPwould becomeW.
- E.G.
Examples:
f("0PLM",1) = 1QAZ
f("ZXCVB",2) = CVBNM
f("HELLO",3) = LYDDW
f("0PLM",11) = 1QSV
f("0PLM",2130) = 0PHX
Rules
- This is code-golf, lowest byte-count wins.
This is slightly more difficult than it seems at first glance.
2Are we allowed to take the input as character-array instead of string? Currently assumed we, but forgot to ask.. – Kevin Cruijssen – 2018-02-05T14:51:03.980
@KevinCruijssen shrug sure, it's not too outlandish. Unless it saves you a byte to break a tie I'm not complaining. – Magic Octopus Urn – 2018-02-05T22:43:35.283