30
4
The three rows of the qwerty keyboard are qwertyuiop
, asdfghjkl
and zxcvbnm
. Your task is to find the longest word that can be typed using only one row of the keyboard, from a given list of words.
Sample input 1
artist
home
gas
writer
geology
marine
twerp
Output
writer
(Of the given words, only gas
, writer
and twerp
can be written using a single row, and writer
is the longest)
The words may not be actual words (so don't assume the third row to be invalid). However, you can assume that there will always be exactly one answer (no more, no less).
Sample input 2
wrhuji
bxnzmmx
gllwssjjd
vnccbb
lrkjhgfdsa
tttttt
Output
bxnzmmx
Additional punctuation and whitespaces can be provided in input (as per language requirements). However, no extra output should be given. Input and output are in lower case. Shortest code wins.
@MartinBüttner I would really like to see how this could be solved with Retina. Do you think it is easily done? – Jerry Jeremiah – 2016-03-17T05:51:01.073
Are the input words always in lowercase? – nimi – 2016-03-17T05:59:14.397
@nimi Yes, they are. – ghosts_in_the_code – 2016-03-17T06:20:33.110
@ghosts_in_the_code You should state that in the challenge for clarity – Luis Mendo – 2016-03-17T09:00:50.747
@JerryJeremiah it's doable but finding the largest of them will likely dominate the code and make it uncompetitive. I'll add an answer later today. – Martin Ender – 2016-03-17T10:25:05.673
So no newlines/ANSI color codes/other non-suppressible output? – CalculatorFeline – 2016-03-17T15:49:48.717
I wonder if the shortest way of handling the "row checking" is not to just list out all the keystrokes. If a language has built-in separation of vowels and consonants, that might be an advantage. Nearly half of the top row is every vowel except A; the next row contains A and S and all consonants from D through L. The bottom row is almost entirely pairs if you treat X and Z as next to each other in a list of consonants). – TOOGAM – 2016-03-17T17:16:07.003
6
Relevant xkcd: https://what-if.xkcd.com/75/
– John Dvorak – 2016-03-17T17:35:52.213@JerryJeremiah There you go.
– Martin Ender – 2016-03-17T21:58:08.653@MartinBüttner thanks so much. I am just facinated by retina but not competent enough to solve these problems myself. – Jerry Jeremiah – 2016-03-17T22:42:38.630
@MartinBüttner Can you please see my sandoboxed post here? It has not received enough attention and I'm not confident of actually posting it.
– ghosts_in_the_code – 2016-03-19T10:51:55.857