Python - Bytes: 4411, False +ves: 0, False -ves: 0 = Score: 4411
import base64,zlib,sys;T=eval(zlib.decompress(base64.b64decode("eNqdXEF24zYMPY43XHTdG/QYskjbGlGUSlFONH25e8cehySAD8rtLPIyji2JIPDx8QH6n9Nfpz//OZ3+/OPLnLrXr+bUP36Ljx/z48eafzze+OufOaX83uHx2/3x4/nb8w97ea85ueqDv/57zpfd8vuffzW/r+LIfezjf7Z6z/Xxe5dvF+o7xfx5Bx/A/L7v60qXvMhyOSsX6fLb8usDfcmcpmyNsrBAV/f8oH/89yPfcpd2LUvo8vPs4CLVcgJZ8MtC+YIhP5plb4lip+b8yDe48l9vWfMKgF32fK+ULTqJ7bjRzbvSG4Al/f7D8vjvQs0T6+t66T1rfqCx2q2Yn+v5p53/qXg0vZrLH+mqjyS2HWXzLV1AcfctP0CQe5XqNSVq0ed9n8E50mszn8pX7PPrI13Py1y+eoF5CjDnUpa68svF/GnmV7XdyjUBpFyyabyEAGbs18pucn9itiEECWrmEv2+tvqGwoNFfq/YSOLfjT5MjRvCiiFf2nHMcxKCerqx1Jl87YI1sAS2phJOC9+0Vd54zgvpRWT3Gdp9vmYSofx9kRUEefkcdxBTwclZoDtFA1Otsc4qUa6EBdNr7y0AB7RdqXbC2mZ8rR1PdU9nv6B89b3SwPPLlK1Lkt65rLpKAgu1ihPureW24tIJ7M8lPwOLszMMhy/gigQnFQDvQe6cyU4ZCV2WcpABmauEqEIhyiub3JdI/VvNTVEmocShMuqLraEYXK8YbhVbSzKIARimh0OkoXerL7uzvQPovdUAUrO84oQW7QNx4w6G5JknFAvIjpbQRg63I3VwyVJZWKPUXyHNRh0OJ7EvBkmOJwKG03P+MdHNu2KvZWFJvbbkn7vwlwGSFW7L165/CCwsnNnpJUL+HUKOqdgkTE+D9B8BvBbSH0oYREKteRAkVoZjgKke0wriLPz2g9nPyvSDgoNaznLnH7ibz/y+AXKz4lhkHy3elKCGw+v/nt9EuOvLAPWjVjjyyZ8PeWhNiG4yRdpcPxCnvua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:
C=c.lower()
if c in t:t=t[c]
elif f and C in t:f=0;t=t[C]
else:t={}
print""in t
This is a python program that expects one command line argument, the word
. From the list of words I constructed a trie, zlib'ed the argument and finally encoded it with base64. If the word is in the trie, the program prints True
, otherwise it prints False
. I wanted to create a spell checker that has 100% accuracy.
I could substantially decrease the number of characters, by not encoding the zlib'ed string (specifically, zlib'ed string is 1113 characters shorter than base 64 encoded), but I wanted to have a code that you can copy/paste directly.
Examples
$python check.py colour
True
$python check.py Colour
True
$python check.py coLoUr
False
$python check.py color
False
$python check.py Color
False
$python check.py I
True
$python check.py i
False
The trie is traversed with characters of the word
, each time getting a new trie from the key of current character. If the word is in the trie, then a ""
must be present in the final trie.
Ungolfed version
import base64, zlib, sys
TRIE = eval(zlib.decompress(base64.b64decode("eNqdXEF24zYMPY43XHTdG/QYskjbGlGUSlFONH25e8cehySAD8rtLPIyji2JIPDx8QH6n9Nfpz//OZ3+/OPLnLrXr+bUP36Ljx/z48eafzze+OufOaX83uHx2/3x4/nb8w97ea85ueqDv/57zpfd8vuffzW/r+LIfezjf7Z6z/Xxe5dvF+o7xfx5Bx/A/L7v60qXvMhyOSsX6fLb8usDfcmcpmyNsrBAV/f8oH/89yPfcpd2LUvo8vPs4CLVcgJZ8MtC+YIhP5plb4lip+b8yDe48l9vWfMKgF32fK+ULTqJ7bjRzbvSG4Al/f7D8vjvQs0T6+t66T1rfqCx2q2Yn+v5p53/qXg0vZrLH+mqjyS2HWXzLV1AcfctP0CQe5XqNSVq0ed9n8E50mszn8pX7PPrI13Py1y+eoF5CjDnUpa68svF/GnmV7XdyjUBpFyyabyEAGbs18pucn9itiEECWrmEv2+tvqGwoNFfq/YSOLfjT5MjRvCiiFf2nHMcxKCerqx1Jl87YI1sAS2phJOC9+0Vd54zgvpRWT3Gdp9vmYSofx9kRUEefkcdxBTwclZoDtFA1Otsc4qUa6EBdNr7y0AB7RdqXbC2mZ8rR1PdU9nv6B89b3SwPPLlK1Lkt65rLpKAgu1ihPureW24tIJ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9ccRiok+HO4v07l6tLUiw4/FHWrluDc2nw/N2ATMh/F0ifCTfS+BrzvU7VSOrN+sd+TiIhWhNtR2eE62/+0hgKZ51G+GcT+21NySDEdtOPHB7OPAetTkeNuY2giOB5uCruByUyWyznj6ev+3pMD5QFpqny2pIsvC8llOHHjRIBUOvSLdIre9fUahqPPhGH/Q9dSoqEyi+tSYsU2NERITZoahEv9aOqdEJy4+x8Z0q8jgbPJpX14rIP2PjdMGsOShKv5L0eq2nzQ+D7vDw7ztfW9T6pit6MryDiQ+NVmlfU8KCpzgdJbwGWuwnONNMzFyXc/8CxiN8aA==")))
trie = TRIE
first = True
for character in sys.argv[1]:
CHARACTER = character.lower()
if character in trie:
trie = trie[character]
elif first and CHARACTER in trie:
first = False
trie = trie[CHARACTER]
else:
print False
if "" not in trie:
print False
print True
Construction of base 64 encoded, zlib'ed trie
f = file("dictionary","r")
END = ""
TRIE = {}
def addWord(word):
trie = TRIE
for character in word:
trie = trie.setdefault(character, {})
trie.setdefault(END, 0)
for line in f.readlines():
l = line.replace("\n", "")
addWord(l)
import zlib, base64
compressed = zlib.compress(str(TRIE).replace(" ", ""), 9)
print base64.b64encode(compressed)