14
4
The keyboard layout people commonly use is the QWERTY layout as shown below.
But there are also other keyboard layouts:
DVORAK
COLEMAK
Your task
Your code will take two inputs: the name of the keyboard layout and a string to transcribe. Your goal is to convert your QWERTY input as if you were typing with the keyboard layout given as first parameter.
Rules
The input format is free, you can use strings, arrays, etc. Moreover, you can use any three distinct values to represent the layouts to reduce your byte count, but they each have to be representable in 10 bytes or less.
You need only to handle the keys with a white background. Specifically, you must transpose the printable ASCII characters from the QWERTY alphabet to one of the other alphabets:
QWERTY: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
DVORAK: !_#$%&-()*}w[vz0123456789SsW]VZ@AXJE>UIDCHTNMBRL"POYGK<QF:/\=^{`axje.uidchtnmbrl'poygk,qf;?|+~
COLEMAK: !"#$%&'()*+,-./0123456789Oo<=>?@ABCSFTDHUNEIMKY:QPRGLVWXJZ[\]^_`abcsftdhuneimky;qprglvwxjz{|}~
WORKMAN: !"#$%&'()*+,-./0123456789Ii<=>?@AVMHRTGYUNEOLKP:QWSBFCDXJZ[\]^_`avmhrtgyuneolkp;qwsbfcdxjz{|}~
(Note: this was transcribed by hand by @ETHproductions, so if you see any errors, please point them out!)
Example
DVORAK zZxX
as input will give as output ;:qQ
This is code-golf so the shortest answer in bytes wins!
1Also, some more test cases would be useful. – ETHproductions – 2017-04-28T15:30:13.950
@ETHproductions I'll had some more test cases – None – 2017-04-28T15:37:14.460
When you say "you can use any three distinct values to represent the layouts", do you mean that we can assume the existence of constants containing those layouts? – Tutleman – 2017-04-28T16:42:27.770
1@Tutleman Yes, you can take 0 1 2 for instance – None – 2017-04-28T17:36:03.883
1Wait, can we take e.g.
!_#$%&-()*}w[vz0123456789SsW]VZ@AXJE>UIDCHTNMBRL"POYGK<QF:/\=^{`axje.uidchtnmbrl'poygk,qf;?|+~
as the input for the Dvorak keyboard? That would trivialize the challenge... How about introducing a length restriction or something similar? – ETHproductions – 2017-04-28T18:38:16.473@ETHproductions Indeed I didn't think about that aspect, you can edit the question if you want to otherwise I'll do it later :) – None – 2017-04-28T18:42:46.627
There, I think it's better now. – ETHproductions – 2017-04-28T18:46:05.003
To clarify: When you say we can take input as an array, do you mean we can use an array of the individual characters in the string? e.g.,
["z","Z","x","X"]
– Shaggy – 2017-04-29T09:51:33.043@Shaggy Yes of course – None – 2017-04-29T09:55:00.773
Cool, that saves me few bytes :) For future reference, when people mention standard means of input in their questions, is a string destructures into an array usually included or is it something that has to be specifically allowed? – Shaggy – 2017-04-29T10:00:15.313
@ETHproductions "they each have to be representable in 10 bytes or less" I'd recommend removing this requirement. – Erik the Outgolfer – 2017-04-29T10:09:01.587
1@EriktheOutgolfer But then you could take e.g.
!_#$%&-()*}w[vz0123456789SsW]VZ@AXJE>UIDCHTNMBRL"POYGK<QF:/\=^{`axje.uidchtnmbrl'poygk,qf;?|+~
as input – ETHproductions – 2017-04-29T11:05:15.233@ETHproductions Maybe add a rule then saying that the input must not be used to construct the layouts, but only to index them? – Erik the Outgolfer – 2017-04-29T13:20:58.783
@EriktheOutgolfer I think that would be a little too blurry. Could I use
E
,S
, andH
(the keys on Qwerty-D
) as my inputs? Why do you think the 10-byte requirement is not a good idea? – ETHproductions – 2017-04-29T13:54:59.2631@ETHproductions Yes you could use those characters as inputs, although the layouts must not depend on them at all to be constructed. The only use for them would be to choose which layout to use. 10 bytes is a fixed limit (IMO too short), that's why I don't like it. And yes you say bytes not chars. I think this should've been sandboxed for more time. – Erik the Outgolfer – 2017-04-29T13:59:54.913
@EriktheOutgolfer I actually quite like the challenge of trying to use those 10 bytes to do as much as possible! – Jonathan Allan – 2017-04-30T03:40:27.723