XKCD:キーボードマッシュ異常


16

別のXKCDに触発された競争。これはKeyboard Mashに基づいています。

入力文字列が与えられたら、標準のUS QWERTYキーボードの 1行に大部分が入力されたと仮定して、異常な文字を特定します。入力文字列にはシフトされたキーストロークを含めることができますが、キャリッジリターン(Enter)、CTRL / ALTの影響を受ける文字、スペース、タブ、およびバックスペースは含まれません(これはばかげているためです)。このチャレンジでは、テンキーはキーボードの一部とは見なされません。

課題は、単一の文字列の個々の文字の大半と同じキーボード行にない文字を出力することです。出力には、各異常文字が1回だけ含まれ、他の文字は含まれません。

2つ以上の行で異常な文字の数が等しい場合、タイブレークは次の順序で決定されます。

  • 最短の一意のリスト
  • 一番上の行

入力

STDIN、ARGV、または関数パラメーターのいずれかを介した文字列

出力

STDOUTへの文字列または関数が戻ります。それぞれの異常なキャラクターは一度だけ持つべきですが、注文する必要はありません。

入力: FJAFJKLDSKF7KFDJ
出力: 7

入力: ASDF11111の
出力: ASDF

入力: lkjrhsDdftkjhrksRjd
出力: rtR

入力: } * 3%&2098 @ $ 2k234#@ $ M
出力: }

返された一番上の行リスト
入力: ASD!@#Vcx
出力:!@#

返される最短の一意のリスト
入力: ASdf1233qwER
出力: 123

返される最上部の最短リスト
入力: 12334QWTTSDFDSXVVBBX
出力: QWT

これはコードゴルフなので、最短のエントリーが勝ちです。

回答:


8

CJam、111 89 88 86 84 83バイト

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

CJamインタープリターでオンラインで試してください。

使い方

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.

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.