Corrcey my Soellign


10

はじめに

私の電話を使っているとき、私がずさんなタイパーだと気付いた方もいるでしょう。だからこそ、私のタイプミスを修正するプログラムを書いてほしいのです。

Chalkrnge

スペルミスのある単語を指定して、私が書くつもりの可能性のあるすべての単語を出力します。

Typso

私のタイプミスの主な原因は、間違ったキーを押し、隣のキーを頻繁に押すという事実にあります。以下は私のキーボードレイアウトです。

q w e r t y u i o p
 a s d f g h j k l
   z x c v b n m
   , [ space ] .

下の行は、, [ space ] .この課題では使用されないことに注意してください

どういうわけか、私は水平方向に間違いを犯すだけです。jではなくnをヒットすることはありませんが、dの代わりにfをヒットする可能性があります。

たとえば、sloppyという単語のスペルは次のようになります。

akioot

各キーの左側に行ったところ。

ただし、必ずしも単語のすべての文字を間違えるわけではないことを忘れないでください。

Ezsmple

入力が次のとおりだとします。

vid

言葉が可能性があった可能性があります:

vid cid bid
vis cis bis
vif cif bif
vod cod bod
vos cos bos
vof cof bof
vud cud bud
vus cus bus
vuf cuf buf

それらのうち、以下は辞書にあります:

cod
cud
bid
bud
bus

したがって、これが出力になります。

ルール

辞書としてここにあるテキストファイルのみを使用してください:http : //mieliestronk.com/corncob_lowercase.txt。このファイルをバイト数の一部として数える必要はありません。

すべての入力は単一の単語になります。出力は任意の方法で表示できます(ある種のセパレータがある限り)。

すべての入力で、辞書にあるバリアントが見つかるとします。

Wibninf

バイト単位の最短コードが優先されます。


11
タイトルを見たとき、これはウェールズ語の別の挑戦になると思った...
— マーティンエンダー

辞書の圧縮は課題の一部であると思います。ファイルから辞書を読み取ることを選択した場合、その長さをスコアにカウントする必要がありますが、それをまだ読んでいない人のために明示する必要がありますメタ全体。PSサンドボックスに何かを投稿する場合は、フィードバックを得るのに十分な時間そこに置いてください。
— Peter Taylor

@PeterTaylorよくありませんが、主に非圧縮で実行できる辞書の解析のみです。
— Beta Decay

ファイルをインライン化した場合、何を数えますか?区切りに2バイト""?
— Peter Taylor

@PeterTaylorまあはい
— ベータ崩壊

回答:


1

Japt、50 47バイト

;D=R+Dv;W=3pUl¹óW ®s3 s1 £DgDbUgY)-X+1}Ãf@~V·bX

入力は修正する単語で、辞書は文字列です。オンラインでテストしてください!(注:辞書を文字列に手動で貼り付ける必要があります。)

使い方

;D=R+Dv;W=3pUl¹óW ®s3 s1 £DgDbUgY)-X+1}Ãf@~V·bX  // Implicit: U = input, V = dictionary, R = newline
;                                                // Re-assign preset variables. D = "QWERTYUIOP\nASDFGHJKL\nZXCVBNM";
 D=R+Dv;                                         // Convert D to lowercase and prepend a newline.
        W=3pUl¹                                  // Set W to 3 to the power of U.length.
               óW                                // Create the range [W, W+W).
                  ®                       Ã      // Map each item Z in the range by this function:
                   s3                            //  Take Z.toString(3).
                      s1                         //  Remove the first character.
                                                 //  If the input is two chars long, e.g. "id", the array is now
                                                 //  ["00", "01", "02", "10", "11", "12", "20", "21", "22"].
                         £            }          //  Map each char X and index Y in the string by this function:
                              UgY                //   Get the char at position Y in U.
                            Db   )               //   Take the index of the char in D.
                                  -X+1           //   Subtract X and add 1.
                          Dg                     //   Get the char at that position in D.
                                                 // This maps our array for "id" to:
                                                 // ["of", "od", "os", "if", "id", "is", "uf", "ud", "us"].
                                        f@       // Filter to only the items X where
                                             bX  //  the index of X in
                                           V·    //  the dictionary, split at newlines,
                                          ~      //  is not -1.
                                                 // This filters our array for "id" to:
                                                 // ["of", "if", "id", "is", "us"].
                                                 // Implicit: output last expression

2

Pythonの2.7、161の 159バイト

from itertools import*
lambda a,k=' qwertyuiop asdfghjkl zxcvbnm ':set(map(''.join,product(*[k[k.index(l)-1:k.index(l)+2].strip()for l in a])))&set("<dictionary>".split())

読み取り可能なバージョン

from itertools import *
dictionary=set("<dictionary>".split())
keyboard=' qwertyuiop asdfghjkl zxcvbnm '
x=[]
for letter in input():
 index=keyboard.index(letter)
 x.append(keyboard[index-1:index+2].strip())

words=set(map(''.join,product(*x)))
print words&dictionary
  • @TuukkaXのおかげで1バイト節約

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