My Problem

At my current place of employment, I single-handedly (ok dual-handedly because I'm missing no limbs) maintain approximately 700 laptops. Due to the nature and frequency of their use, I often find they are returned with a bit of damage. For this problem, my primary concern is when a laptop is returned with a broken or defunct keyboard. When the hardware repairman fixes these broken keyboards, it becomes necessary to test them. The test involves using each...and...every...single...key. What a drag right? The problem is, sometimes I lose track of if I typed a key or not.

A solution?

Write a program/script that:

  1. Takes user input
  2. Upon submission (in whatever way you deem fit), determines whether each key was pressed.
  3. Outputs yes or no or any way to indicate that either I was successful in pressing all the keys or not. (Indicate in your answer the two possible outputs if it's not something obvious).


  1. Uppercase, lowercase, both? Whichever way you deem fit. As long as it's [A-Z], [a-z] or [A-Za-z]. Same goes with numbers and other symbols. (So if = was typed in, + doesn't matter). Your choice if you want to include shifted characters or not.
  2. You needn't worry about tabs or spaces
  3. No needs for function keys, CTRL, ALT, Esc or any other keys that don't output something on the screen
  4. This assumes an EN-US keyboard and the laptops do not include a numpad.
  5. OS agnostic, whatever language you prefer
  6. It doesn't matter if the key has been pressed multiple times (for when the tester just gets lazy and starts button smashing like it's Mortal Kombat)

Here's a potential input set that would return true (or yes, or "You did it!")


Winner is determined by the least number of characters.

  • \$\begingroup\$ Do we need to check that each keystroke appears at least once or exactly once? \$\endgroup\$
    – xnor
    Commented Jun 7, 2014 at 14:04
  • \$\begingroup\$ @xnor, If it appears multiple times, it's ok. I updated the question. \$\endgroup\$ Commented Jun 7, 2014 at 14:10
  • 1
    \$\begingroup\$ Okay then, that isn't worth it. \$\endgroup\$
    – user344
    Commented Jun 7, 2014 at 15:34
  • 1
    \$\begingroup\$ @ChristopherW If this is an ongoing issue for you, you should have a look at this website keyboardtester.com. \$\endgroup\$
    – gxtaillon
    Commented Jun 7, 2014 at 15:39
  • 2
    \$\begingroup\$ @MomemtumMori, that hand doing the Pennsylvania Dutch keyboarding technique over in the side bar? Totally mine. \$\endgroup\$ Commented Jun 7, 2014 at 15:44

9 Answers 9


GolfScript, 11

Printable ASCII isn’t that interesting…


Ruby, 68

With flag -rset for 4 characters.

p Set.new(?`..?z)+(?,..?9)+%w{[ ] \\ ; '}==Set.new(gets.split'')


Python 3, 76

  • 1
    \$\begingroup\$ I'd suggest posting these in two separate answers. \$\endgroup\$
    – user344
    Commented Jun 7, 2014 at 15:42

JavaScript - 62 70


And a bit shorter:


CJam - 9


It checks for the "shifted" characters too (including uppercase letters).
Try it at http://cjam.aditsu.net/

Note: there is an invisible character (with code 127) after the apostrophe.

  • \$\begingroup\$ “It checks for the "shifted" characters too (including uppercase letters).” I’d say that’s incorrect behaviour. \$\endgroup\$
    – Ry-
    Commented Jun 7, 2014 at 15:48
  • \$\begingroup\$ @minitech "Your choice if you want to include shifted characters or not." \$\endgroup\$ Commented Jun 7, 2014 at 15:49
  • \$\begingroup\$ But right before that, it says “Uppercase OR lowercase” (that’s exclusive, right?) \$\endgroup\$
    – Ry-
    Commented Jun 7, 2014 at 15:51
  • \$\begingroup\$ @minitech, I updated the question. Sorry. That OR is misleading. \$\endgroup\$ Commented Jun 7, 2014 at 15:54
  • \$\begingroup\$ @ChristopherW My program will print 0 on your example input, but if you also press all those characters while holding shift, it will print 1. Is that ok? \$\endgroup\$ Commented Jun 7, 2014 at 15:59


    foreach (str_split("`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./") as $v) {
        if (strpos($_GET['i'],$v)!==false)die(NO);

$_GET['i'] is the input

  • 1
    \$\begingroup\$ Use $_GET to save 1 char if it's acceptable. \$\endgroup\$
    – tomsmeding
    Commented Jun 8, 2014 at 22:53
  • \$\begingroup\$ @tomsmeding, yeah I did :) \$\endgroup\$ Commented Jun 9, 2014 at 4:35
  • \$\begingroup\$ You can add a padding character (é or something) to the front of your string and remove the !==false to save 8 characters, then the braces for 4 more. register_globals makes this "é$i". die(NO) is also possible. \$\endgroup\$
    – Ry-
    Commented Jun 10, 2014 at 3:24
  • \$\begingroup\$ @minitech - I dont know what you say, padding character ? feel free to edit my answer instead \$\endgroup\$ Commented Jun 10, 2014 at 4:46

GolfScript, 6 bytes


If all ASCII characters with codes between 33 and 127 are present, it prints 1. Otherwise, it prints 0.

This approach will fail if the input contains other characters (including a final newline), which has been allowed by the OP and is also true for the existing GolfScript solution.


$ echo -n '!"#$%&'"'"'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~' |
> golfscript <(echo '.&,94=')

How it works

.&  # Compute the intersection of the input string with itself. This removes duplicates.
,   # Compute the length of the resulting string.
94= # Push 1 if the length is 94, otherwise push 0.
  • \$\begingroup\$ The comment you linked doesn't say the input won't contain a newline (or other characters outside of 33-126), it just says it will only contain valid characters. Is newline an invalid character? \$\endgroup\$ Commented Jun 10, 2014 at 11:29
  • \$\begingroup\$ By valid I meant in the range we're testing against, but I guess I should have expressed myself more clearly when asking the OP... \$\endgroup\$
    – Dennis
    Commented Jun 10, 2014 at 13:49

Python 72:

f=lambda x:set(x)==set("`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./")
  • 3
    \$\begingroup\$ The OP asked for a program that takes user input. \$\endgroup\$
    – user344
    Commented Jun 7, 2014 at 15:43

Haskell, 41 (two solutions)

interact(\y->show$all(`elem`y)[' '..'`'])

or (point-free style)

interact$show.(`all`[' '..'`']).flip elem

Need to input at least these characters:


in any order, any number of times. Extra characters are allowed. Run in an interpreter. Must hit Enter when you are done, but if you hit Enter before you are done, you can keep entering characters, and press Enter again. Will print True if you have hit every character, otherwise it won't print anything.


Perl, 70 characters

say[sort grep!$s{$_}++,<>=~/\S/g]~~[sort"',-./;=[\]`"=~/./g,0..9,a..z]


echo `134223423567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./ | perl -E 'say[sort grep!$s{$_}++,pop=~/\S/g]~~[sort"',-./;=[\]`"=~/./g,0..9,a..z]'

Prints 1 if all keystrokes present, else prints nothing.

  • \$\begingroup\$ Requires Perl 5.10+ \$\endgroup\$
    – Zaid
    Commented Jun 8, 2014 at 18:25
  • \$\begingroup\$ In most shells, your example will fail since some of the characters in the echoed string require escaping. \$\endgroup\$
    – Dennis
    Commented Jun 9, 2014 at 21:27

C, 97 characters

main(long a,char**u){a=0xfb0000000750003d;for(u++;**u;a|=2L<<*(*u)++-39);a=48+!~a;write(1,&a,1);}

Need to call the program with argument containing at least the letters:


and get answer 1 (true). The charset can be changed by changing the initialization value of a.


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.