Corrcey我的庄严


10

引言

你们中的一些人可能已经意识到使用手机时我是马虎打字机。这就是为什么我要您编写一个纠正我的错字的程序。

粉笔

给定一个拼写错误的单词,输出我打算写的所有可能的单词。

错字

我输入错误的主要原因是我打错了按键,并且经常打到隔壁的按键。以下是我的键盘布局:

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 ] .将永远不会在此挑战中使用

出于某种原因,我只会在水平方向上犯错误:我永远不会碰到n而不是j,但是我可能会碰到f而不是d

例如,我最终可能将单词sloppy拼写为:

akioot

每个键我都离开的地方。

但是,请不要忘记,我不一定会对单词中的每个字母犯错。

以斯普勒

假设输入为:

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。您不必将此文件计为字节数的一部分。

所有输入将是一个单词。您可以以任何希望的方式显示输出(只要有某种分隔符即可)。

假设所有输入都将在字典中找到一个变体。

维布宁夫

以字节为单位的最短代码获胜。


11
当我看到标题时,我认为这将是关于威尔士的又一个挑战……
Martin Ender

我认为压缩字典是挑战的一部分,并且,如果我选择从文件中读取字典,则应将其长度计入我的分数,但是对于那些未读过字典的人来说,应该明确指出这一点。整个meta。附言:如果您要向沙箱发布内容,请将其放置足够长的时间以获得反馈。
彼得·泰勒

@PeterTaylor好吧,不是真的,主要是字典的解析,可以不压缩地完成。
Beta Decay's

因此,如果我内联文件,我应该算什么?两个字节用于定界""
彼得·泰勒

@PeterTaylor好吧
Beta Decay

Answers:


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'9
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.