16
\$\begingroup\$

Another XKCD inspired competition. This one is based on Keyboard Mash.

Given a input string, identify the anomalous characters, assuming that the majority have been typed on a single row of the standard US QWERTY keyboard. Input strings can contain shifted key strokes, but they will not contain carriage returns (Enter), CTRL/ALT affected characters, spaces, tabs and backspaces (because that would be silly). The number pad will not be considered as part of the keyboard for this challenge.

The challenge is to output the characters that aren't on the same keyboard row as the majority of individual characters in the single string. The output should contain each anomalous character only once and no other characters.

In the case of a equal count of anomalous characters across two or more rows, the tie break is determined in this order:

  • Shortest unique list
  • Top most row

Input

A string through either STDIN, ARGV or a function parameter

Output

A string to STDOUT or a function return. It should have each anomalous character only once, but does not need to be ordered.

Examples

Input: FJAFJKLDSKF7KFDJ
Output: 7

Input: ASDF11111
Output: ASDF

Input: lkjrhsDdftkjhrksRjd
Output: rtR

Input: }*3%&2098@$2k234#@$M
Output: }

Topmost row list returned
Input: ASD!@#Vcx
Output: !@#

Shortest unique list returned
Input: ASdf1233qwER
Output: 123

Topmost shortest list returned
Input: 12334QWTTSDFDSXVVBBX
Output: QWT

This is code golf, so shortest entry wins.

\$\endgroup\$
8
\$\begingroup\$

CJam, 111 89 88 86 84 83 bytes

la9*~"{}qwertyuiop ;':asdfghjkl ,./<>?zxcvbnm"{_32^}%_'ÿ,^a\S%+{[f&s\e|__|]:,}$0=&

Try it online in the CJam interpreter.

How it works

la9*~     e# Push the input 9 times on the stack.

"{}qwertyuiop ;':<STX>asdfghjkl ,./<>?zxcvbnm"

{_32^}%   e# XOR a copy of each character with 32.
_'<DEL>,^ e# Push a string of all ASCII characters that are missing.
a\        e# Wrap it in an array.
S%+       e# Split the string at spaces and concatenate with the array.
{         e# Sort the chunks according to the following:
  [       e#
    f&s   e# Push the string of characters from the input that are in this chunk.
    \e|   e# If the result is empty, replace it with the input.
    __|   e# Push a copy with duplicates removed.
  ]       e# Collect both strings in an array.
  :,      e# Replace each string with its length.
}$        e#
0=        e# Retrieve the minimum.
&         e# Intersect it with the input.
\$\endgroup\$
8
\$\begingroup\$

CJam, 90 88 86 84 83 bytes

This is just a straight forward implementation.

" qwertyuiop[] asdfghjkl;': zxcvbnm<>?,./"_32f^.\_'¦,^\+S%qf{_@--}{},{__&]:,}$0=_&

Try it online here . Pastebin

\$\endgroup\$

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.