40
\$\begingroup\$

Given a character, output (to the screen) the entire qwerty keyboard layout (with spaces and newlines) that follows the character. The examples make it clear.

Input 1

f

Output 1

g h j k l
z x c v b n m

Input 2

q

Output 2

w e r t y u i o p
a s d f g h j k l
z x c v b n m

Input 3

m

Output 3

(Program terminates without output)

Input 4

l

Output 4

z x c v b n m

Shortest code wins. (in bytes)

P.S.

Extra newlines, or extra spaces at the end of a line are accepted.

\$\endgroup\$
8

40 Answers 40

1
2
0
\$\begingroup\$

Gema, 56 characters

?=@subst{\\A\*?=\;\?=\? ;qwertyuiop\nasdfghjkl\nzxcvbnm}

Sample run:

bash-4.3$ echo -n 'f' | gema '?=@subst{\\A\*?=\;\?=\? ;qwertyuiop\nasdfghjkl\nzxcvbnm}'
g h j k l 
z x c v b n m 
\$\endgroup\$
0
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟, 32 chars / 79 bytes

⟦ɘƄ瀛ذ鸊ް΀ꀆဓƘ᳀ᘁ堍怍訁码聮Ęݠⶰ䀀#]ø⬭Čï⎖1

Try it here (Firefox only).

At least I'm winning in char count... (Byte count's a different story.)

Oh yeah, just realized that I implemented index shortcuts (⎖1 instead of [1]) awhile back. Silly me!

\$\endgroup\$
2
  • \$\begingroup\$ What language is this? or is it literally this: i.imgur.com/WC7XvYs.png (and is there documentation) it's weird, aha! \$\endgroup\$
    – ʰᵈˑ
    Nov 26 '15 at 11:51
  • \$\begingroup\$ This is ESMin. Letters are in doublestruck, so you might have trouble seeing them. See github.com/molarmanful/ESMin (docs are outdated, though). \$\endgroup\$ Nov 26 '15 at 15:44
0
\$\begingroup\$

C++, 129, 112 97 bytes

#include<string>
#include<cstdio>
void o(char c){puts(strstr("qwertyuiopasdfghjklzxcvbnm",&c));}

Ungolfed:

#include<string>
#include<cstdio>
void o(char c)
{
    puts(strstr("qwertyuiopasdfghjklzxcvbnm",&c));
}
\$\endgroup\$
7
  • \$\begingroup\$ You could shave off 17 bytes by using puts instead of std::cout<< \$\endgroup\$
    – DJMcMayhem
    Nov 26 '15 at 5:36
  • \$\begingroup\$ @DJMcMayhem Thanks! An excellent point: for some reason I thought I would still need an #include for puts, but evidently I do not! \$\endgroup\$
    – Tas
    Nov 26 '15 at 5:40
  • \$\begingroup\$ Also, this is another 12 shorter. \$\endgroup\$
    – DJMcMayhem
    Nov 26 '15 at 5:48
  • \$\begingroup\$ Thanks! I didn't even know strstr was a thing. \$\endgroup\$
    – Tas
    Nov 26 '15 at 5:55
  • \$\begingroup\$ I think that's a little bit overgolfed. You need <stdio.h> for strstr. \$\endgroup\$
    – DJMcMayhem
    Nov 26 '15 at 6:10
0
\$\begingroup\$

Batch, 206 + 2 = 208 bytes

Because this uses delayed expansion you need to invoke it with CMD /V /C keyboard.cmd <letter>, so adding 12 for the /V switch.

@echo off
set a=q w e r t y u i o p
set b=a s d f g h j k l
set c=z x c v b n m
if not "!a:*%1 =!"=="!a!" echo !a:*%1 =!
if not "!a:*%1=!!b:*%1 =!"=="!a!!b!" echo !b:*%1 =!
if not %1==m echo !c:*%1 =!
\$\endgroup\$
1
  • \$\begingroup\$ I'm afraid the command line option would count 1 if cmd would accept it as /VC, like POSIX tools do. But as I know /V requires its own /, which also gets counted. \$\endgroup\$
    – manatwork
    Nov 27 '15 at 7:37
0
\$\begingroup\$

Python, 109 bytes

I know its a bit large but its all I know how to do right now!

def kb(c): 
 s = "q w e r t y u i o p \n a s d f g h j k l \n z x c v b n m"
 a = s.split(c)
 print(a[1])
\$\endgroup\$
2
  • \$\begingroup\$ I don't think you need the call to kb() at the end; defining the function is enough. Also, 1 space of indentation is enough. After making these changes, I get 108 bytes, using this site. \$\endgroup\$ Nov 27 '15 at 20:51
  • \$\begingroup\$ @ETHproductions wow I didn't know that once space thing. (New to python). Thanks again for your help! \$\endgroup\$ Nov 27 '15 at 21:03
0
\$\begingroup\$

Bash, 80 bytes

x="qwertzuiop\nasdfghjkl\nyxcvbnm"&&echo -e ${x#*$1}|sed 's/./& /g'

Try it yourself, either replace $1 with desired character or make a #!/bin/bash script.

Here are some samples from cygwin:

$x="qwertzuiop\nasdfghjkl\nyxcvbnm"&&echo -e ${x#*q}|sed 's/./& /g'
w e r t z u i o p
a s d f g h j k l
y x c v b n m

$x="qwertzuiop\nasdfghjkl\nyxcvbnm"&&echo -e ${x#*m}|sed 's/./& /g'

$x="qwertzuiop\nasdfghjkl\nyxcvbnm"&&echo -e ${x#*h}|sed 's/./& /g'
j k l
y x c v b n m

It's not the shortest, but I'm still proud of it!

\$\endgroup\$
0
\$\begingroup\$

PHP, 83 bytes

<?=trim(explode($argv[1],"qw e r t y u i o p
a s d f g h j k l
z x c v b n m")[1]);

Takes the letter from the command line, like:

$ qwerty.php y
\$\endgroup\$
0
\$\begingroup\$

Bash, 74 bytes

Took a different approach than @Cajova_Houba's answer, so I posted it separately. Ended up not being too much shorter because I initially forgot to deal with space-separating the output.

cut -d"$1" -f2<<<"qwertzuiop asdfghjkl yxcvbnm"|tr ' ' "\n"|sed 's/./& /g'

Takes input as a command line argument, or just replace $1 manually and run it straight from terminal.

\$\endgroup\$
0
\$\begingroup\$

Haskell, 79 bytes

drop 2.snd.(`span`"q w e r t y u i o p\na s d f g h j k l\nz x c v b n m").(/=)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

C (gcc), 57 bytes

f(c){puts(strchr("qwertyuiop\nasdfghjkl\nzxcvbnm",c)+1);}

Try it online!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.