# Output the qwerty keyboard

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.

• Is a function sufficient or do you require a full program that reads/writes to stdin/stdout? Nov 24, 2015 at 14:47
• @agtoever As per meta.codegolf.stackexchange.com/questions/7562/…, it is allowed. However, the function must still output to the screen . Nov 24, 2015 at 14:56
• @agtoever Try this link instead. meta.codegolf.stackexchange.com/questions/2419/… Nov 24, 2015 at 15:06
• are leading space before a line allowed? Nov 27, 2015 at 21:56
• @SahilArora Nope. Nov 28, 2015 at 3:24

## CJam, 42 40 bytes

"wertyuiop asdfghjkl zxcvbnm"q/W=S%Sf*N*


Test it here.

### Explanation

"we...nm"
e# Push the letters in order, without q. We don't need q, because it will never
e# be part of the output.
q/   e# Split the string around the input. If the input is "q", the entire string
e# will go into a single chunk.
W=   e# Select the last chunk.
S%   e# Split the string around spaces, discarding empty segments (only relevant for the
e# first segment if the input is "p" or "l").
Sf*  e# Join each line by spaces.
N*   e# Join the lines by linefeeds.

• What is e#? Is it the CJam syntax for a comment? Thanks in advance.
– A.L
Nov 25, 2015 at 12:38
• @A.L yes it is. Nov 25, 2015 at 12:48

# Pyth, 33 bytes

jjL\ cec."zÈ´ýß44,ûtKÕÀ@"z\


Note that some characters are unprintable. Try it online in the Pyth Compiler.

### How it works

jjL\ cec."z…"z\

."z…"     Unpack …, with lowest character '' and highest character z.
c      z    Split at occurrences of the input (z).
e            Retrieve the last resulting chunk.
c         \  Split into rows, at backticks.
jL\               Separate the characters of each row by spaces.
j                  Separate the rows by linefeeds.

• Aw man, I had just created my first Pyth program ever (only 38 bytes!), then you came along... +1 BTW, I think \  is equivalent to d. Nov 24, 2015 at 18:01
• Oops, I guess it's not the same... what's different? Nov 24, 2015 at 18:06
• @ETHproductions @Dennis Same reason why md5 doesn't produce 5 spaces. d is the default variable that iterates through the iterable argument of the map operator. And jL\ <list> is simply a shortcut for the map operator mj\ d<list>. Nov 24, 2015 at 18:58
• @Jakube Oh, that makes sense. Thanks! Nov 24, 2015 at 19:02

# Perl, 56 bytes

#!perl -p
'qwertyuiop
asdfghjkl
zxcvbnm'=~/$_ ?/;$_=$';s/\B/ /g  Counting the shebang as 3, input is taken from stdin. If a leading newline isn't a concern for inputs p and l, then /$_\n?/ could be replaced with a bare $_ to save 4. Sample Usage $ echo g|perl qwerty.pl
h j k l
z x c v b n m

$echo v|perl qwerty.pl b n m  • Thank you for teaching me about \K! Nov 24, 2015 at 17:06 • @DomHastings in this case, it wasn't really necessary for the byte count, s/.\B/$& /g would work equally well. A better example. Nov 25, 2015 at 0:38

# GS2, 38 37 bytes

♦wertyuiop asdfghjkl zxcvbnm♣B3$,■♪2◙  The source code uses the CP437 encoding. Try it online! ### Test run $ base64 -d > qwerty.gs2 <<< BHdlcnR5dWlvcCBhc2RmZ2hqa2wgenhjdmJubQVCMyQs/g0yCg==
$wc -c qwerty.gs2 37 qwerty.gs2$ echo -n f | gs2 qwerty.gs2
g h j k l
z x c v b n m


### How it works

♦                                      Begin string literal.
wertyuiop asdfghjkl zxcvbnm
♣          End string literal.
B         Swap the string with the input.
3        Split the string at the input character.
$Select the last chunk. , Split the selected chunk at spaces. ■ Map over the resulting array: ♪ Push ' '. 2 Join the characters, separating by ' '. ◙ Push a linefeed.  # JavaScript (ES6), 60 bytes x=>[...qwertyuiop asdfghjkl zxcvbnm].join .split(x)[1]  Uses the same technique as most other answers. Suggestions welcome! • Can you explain why do you use the "...". I try without on JSFiddle and still working? Nov 25, 2015 at 15:14 • @Awashi It is a spread operator. It separates the string into an array of characters. Without it the .join  would do nothing and there would be no spaces in the result. Nov 26, 2015 at 10:18 • @user81655 Tank you Nov 26, 2015 at 11:26 # C#, 112 bytes 105110 Count went up by 5 bytes, but more correct! Thanks @MartinBüttner!! void c(char i){System.Console.Write(@"q 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".Split(i)[1].Trim());}  Un-golfed void c(char i) { System.Console.Write(@"q 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".Split(i)[1].Trim()); }  ## Python, 83 bytes lambda c,s="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":s[s.index(c)+2:]  Try it online # Ruby, 63 57 bytes Takes the character as command line argument: ruby keyboard.rb e "qwertyuiop asdfghjkl zxcvbnm".scan$*[0]
puts$'.chars*' '  # TeaScript, 5045 44 bytes TeaScript is JavaScript for golfing. qwertyuiop asdfghjkl zxcvbnm.s×[1]s(b)j(p)  ### Ungolfed and explanation qwertyuiop asdfghjkl zxcvbnm.s(x)[1]s(b)j(p) // Implicit: x = input string ... // Take the qwerty string, .s(x) // and split it at the input. [1] // Take the second item from this, s(b) // split it into chars, j(p) // and join the result with spaces. // Implicit: output final expression  # JavaScript ES6, 73 f=x=>[...(k=qwertyuiop asdfghjkl zxcvbnm).slice(k.search(x)+1)].join   If a leading newline is not allowed when parameter is p or l, then 83 f=x=>(k=q 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).slice(k.search(x)+2)  # Sed, 59 characters (58 characters code + 1 character command line option.) s/./&qwertyuiop\nasdfghjkl\nzxcvbnm/ s/(.).*\1// s/\w/& /g  Sample run: bash-4.3$ echo -n 'f' | sed -r 's/./&qwertyuiop\nasdfghjkl\nzxcvbnm/;s/(.).*\1//;s/\w/& /g'
g h j k l
z x c v b n m


# Ruby, 86878371 66

puts"qwertyuiop
asdfghjkl
zxcvbnm ".split($*[0])[1].gsub /./,'\& '  The extra space after m is to prevent the program from crashing if the input is 'm'. Thanks to @manatwork for ~16 bytes of tips • Let me guess… Too many Python coding in the last time? Nov 24, 2015 at 16:01 • Some minor syntax changes: ARGV$*; each_charchars; do..end{..}; printf$><< + % would lead to this: "qwertyuiop↵asdfghjkl↵zxcvbnm".split($*[0])[1].chars{|i|$><<"%s "%i}. More in Tips for golfing in Ruby. Nov 24, 2015 at 16:09 • @manatwork First time trying to golf in Ruby, thanks for the tips/link! Nov 24, 2015 at 16:10 • I see you didn't got the hint in my first comment. In Ruby there is no need for triple quotes around multiline strings. (Actually I had no idea until now that it accepted by Ruby.) Nov 24, 2015 at 16:21 • The leading spaces in the output are quite ugly. As . in regular expression does not match \n by default, better use that for the spacing: puts"qwertyuiop↵asdfghjkl↵zxcvbnm ".split($*[0])[1].gsub(/./,'\& '). Though the code length will remain the same. Nov 24, 2015 at 16:38

# PHP, 88 bytes

<?=$m[1&ereg("$argn.(.*)",'q 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',$m)];  Requires the -F command line option, counted as 3. Default .ini setting are assumed (you may disable your local .ini with -n). Sample Usage $ echo g|php -F qwerty.php
h j k l
z x c v b n m

. S Q=$E(A,I) ; Extract 1 letter (at position I) from A and save in Q. . W:B Q," " ; If our print flag (B) is true, print the letter in Q & a space. . X:"qpl"[Q "W !" ; If Q is q, p or l, write a cr/lf . S:Q=P B=1 ; If Q == P (stdin) change our print flag from false to true.  The rule allowing extra newlines saved me almost 10 bytes... # Java - 107 bytes void q(char c){System.out.print("qwertyuiop\nasdfghjkl\nzxcvbnm ".split(""+c)[1].replaceAll("\\w","$0 "));}


Ungolfed with wrapper-class reading from System.in

public class Qwerty {

public static void main(String[] args) {
new Qwerty().q(new java.util.Scanner(System.in).next().charAt(0));
}
void q(char c) {
System.out.print("qwertyuiop\nasdfghjkl\nzxcvbnm ".split(""+c)[1].replaceAll("\\w","$0 ")); } }  If spaces at start-of-line were acceptable, we could go down to 99 bytes: void q(char c){System.out.print("qwertyuiop\nasdfghjkl\nzxcvbnm ".split(""+c)[1].replace(""," "));}  # 8086 machine code + DOS, 61 bytes Hexdump (with ASCII view on the right): B8 1E 01 8B F8 CD 21 B1 1F F2 AE 8B F7 AC 8A D0 ......!......... B4 02 CD 21 80 E2 20 74 02 CD 21 E2 F0 C3 71 77 ...!.. t..!...qw 65 72 74 79 75 69 6F 70 0D 0A 61 73 64 66 67 68 ertyuiop..asdfgh 6A 6B 6C 0D 0A 7A 78 63 76 62 6E 6D 0D jkl..zxcvbnm.  Assembly source code (can be assembled with tasm):  .MODEL TINY .CODE org 100h MAIN PROC mov ax, offset qwerty ; sets ah=1 (coincidence) mov di, ax ; di points to the string int 21h ; reads a char from keyboard into al mov cl, 31 ; cx is the length of the string repne scasb ; look for the char mov si, di ; si now points beyond the found char myloop: lodsb ; load a char mov dl, al mov ah, 2 int 21h ; output the char and dl, 20h ; if it's a letter, set it to a space jz print_done ; if it's not a letter, don't print a space int 21h ; if it's a letter, print a space print_done: loop myloop ; repeat until end of string ret qwerty db 'qwertyuiop',13,10,'asdfghjkl',13,10,'zxcvbnm',13 MAIN ENDP END MAIN  Two fun things here: 1. The offset of the qwerty string is 0x011e. The upper byte of it is 1, which is the DOS function number for character input. This saves 1 byte in the code. 2. All lower-case letters have bit 5 set. When doing an AND with 0x20, they are all turned into a space, which is then printed. If the previous char was an end-of-line byte, it gets turned into 0, and no space is output. This is used to avoid the nonsensical sequence 0d 20 0a 20 at end of line. One almost-fun thing: I tried to search for the input char starting at address 0 (that decreased program size by 2 bytes), instead of the usual place (start of the string). This almost worked; however, it failed for input t, because the code itself contains the byte t (as part of the encoding of a conditional jump). So for t, it would output a few junk bytes: ## Python 2, 5867 63 bytes ## lambda x:" ".join("qwertyuiop\nasdfghjkl\nzxcvbnm".split(x)[1])  Takes input as a string or char. Splits the string at the input and prints off everything after the split. (First time code-golfing, please be gentle :P ) EDIT: Didn't see the additional spaces required between characters, added now EDIT 2: Modified to be an anonymous lambda function and removing the additional split arg, saving 4 bytes • Welcome to PPCG! I don't think you need the space after print, but it seems that this doesn't print the spaces between each pair of letters. Nov 24, 2015 at 16:23 • Can't provide a reference right now, but when the interpreter requires extra formatting of the input, that is also included in the count. (Correct me if I am wrong, but I think this only works if the input is passed together with surrounded quotes, like "f".) Nov 24, 2015 at 16:26 • Nice first golf. Functions are allowed by default, even anonymous ones, so it's shorter to do this as lambda s:.... I think the split doesn't need an arg of 1, since the character appears only once. This outputs spaces at the start of succeeding lines, not sure if that's allowed. – xnor Nov 25, 2015 at 0:28 # Ruby, 59 57 67 bytes Added spaces between letters puts"qwertyuiop\nasdfghjkl\nzxcvbnm".split(gets.chop)[-1].chars*' '  • This fails on input “m”. That can be easily fixed by changing the array index from -1 to 1, but then on input “m” will result nil. Which is not a problem itself, but will cause you problems when finishing your code to add spaces between the letters. Nov 25, 2015 at 8:55 # JavaScript, 88 bytes function s(d){alert("qw e r t y u i o p\na s d f g h j k l\nz x c v b n m".split(d)[1])}  (no need in the space after the first char, as it never gets to the output) Alerts the keyboard when you call s("some letter"). Can be also made with document.write() or console.log(), but hey, it's longer :P Demo: function s(d){alert("qw e r t y u i o p\na s d f g h j k l\nz x c v b n m".split(d)[1])} s(prompt("Enter the key")); • You could probably save a few bytes by just using \n instead of ; in the string and getting rid of the replace. Nov 24, 2015 at 21:18 • @Eth Sure, thanks! I did use the replace, because at first, without counting the line breaks, the replace would shorten. Then I've noticed that the line breaks should be there, so I've used replace again. Didn't even think it could make the code longer :D Nov 24, 2015 at 21:24 SQL (MS T-SQL), 172 bytes CREATE PROC c @I CHAR(1) AS DECLARE @S CHAR(49) SET @S = 'w e r t y u i o p' + CHAR(13) + 'a s d f g h j k l' + CHAR(13) + 'z x c v b n m' PRINT RIGHT(@S,LEN(@S)-CHARINDEX(@I,@S))  Ungolfed: CREATE PROC c -- Create a procedure named "c" @I CHAR(1) -- Which is invoked with a single character input (@I) AS DECLARE @S CHAR(49) = 'w e r t y u i o p' + CHAR(13) + 'a s d f g h j k l' + CHAR(13) + 'z x c v b n m' -- Initialise the entire output omitting "q " as @S PRINT RIGHT(@S,LEN(@S)-CHARINDEX(@I,@S)) -- Use the charindex funtion to effectively substring @S  I'm new here, only just discovered this site. No idea if I've posted correctly or if T-SQL is allowed but I know the procedure above works. # O 2.2, 48 46 characters "qwertyuiop asdfghjkl zxcvbnm "i/r;s{n.U=ST?}d  Sample run: bash-4.3$ ./o keyboard.o <<< 'f'
g h j k l
z x c v b n m


## O, 61 characters

"qwertyuiop\nasdfghjkl\nzxcvbnm\n"i/r;""/rl{.o"\n"={}{' o}?}d


Sample run:

bash-4.3\$ java xyz.jadonfowler.o.O keyboard.o <<< 'f'
g h j k l
z x c v b n m

• This doesn't work on the IDE for some reason, looking into it now...
Nov 26, 2015 at 1:17
• "qwertyuiop\nasdfghjkl\nzxcvbnm\n"i/r;s{n.'\n=ST?}d only works on the new interpreter but is 51 bytes.
Nov 26, 2015 at 1:22
• The permalinks are... a work in progress :P
Nov 26, 2015 at 6:10
• Yup, in the libregexp directory
Nov 26, 2015 at 8:56
• git clone the repo, then git submodule update --init, then make
Nov 26, 2015 at 9:59

# Hassium, 114 Bytes

func main(){k="qwertyuiop\nasdfghjkl\nzxcvbnm\n"foreach(l in k.substring(k.index(input())))print(l!="\n"?l+" ":l)}


Run online and see expanded with test case here

# Japt-hR, 12 bytes

;Dv qU ®·®¬¸


Try it

# Husk, 29 35 bytes

Edit +6 bytes when I realised that the letters need to be separated by spaces

¶mJ' ¶!2x¨qw²yuiop₄sdfghjkl¶zxcvbnm


Try it online!

# Husk, 38 bytes

↓2↓≠←⁰¶mJ' ¶¨qw²yuiop₄sdfghjkl¶zxcvbnm


Try it online!

• I wrote a smug comment thinking that I'd beaten you by 10 bytes, before realising that I hadn't read the question properly... Oct 23, 2020 at 16:33
• @DominicvanEssen No worries, happens sometimes. Oct 23, 2020 at 17:20

# JavaScript, 77 bytes

alert(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.split(prompt())[1])


# K (ngn/k), 53 bytes

{ 0:1_*|x\"\n"/" "/'$$qwertyuiopasdfghjklzxcvbnm}  Try it online! Uses "\n"/" "/'$$......... to (slightly) compress "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".

It then splits that string on the input character, taking the remainder that occurs after that character.