The goal of this challenge is to determine whether a given String can be typed using only one line of a standard UK QWERTY keyboard.
code golf, so shortest solution in bytes wins!
Input will be a single String of zero or more characters in the ASCII decimal range of 32-126 inclusive. You may assume for this challenge that an empty String requires no typing and thus can be typed using a single line.
You may take the input as a String, list of characters, or equivalent form for your language.
Output should be a truthy value for any String that can be typed using a single line, or falsey for one that cannot.
To clarify any ambiguity over what the standard keyboard layout is below is a list of keys available on each line, including alternate upper keys (accessed using shift).
- Line 1
- Line 2
- Line 3
- Special: Caps Lock
- Line 4
- Special: Shift
- Line 5
- Special: Space Bar
Alternate upper keys can only be pressed if Shift is also on the same line, and uppercase keys can only be accessed through Caps Lock or Shift. You really can only use one keyboard line!
-> true (empty string) 45-2=43 -> true (line 1) qwerty -> true (line 2) tryitout -> true (line 2) Qwerty -> false (no shift or caps on line 2) #sad -> true (line 3) AsDf -> true (caps lock used) @sDF -> false (no shift for alternate upper) zxcvbn? -> true (line 4) zxc vbn -> false (spacebar on separate line) 123abc -> false (multiple lines) -> true (just space bar) !!! -> false (exclamation marks cannot be printed by a single line)