Skip to content

Instantly share code, notes, and snippets.

@okaq
Created May 22, 2011 20:32
Show Gist options
  • Save okaq/985859 to your computer and use it in GitHub Desktop.
Save okaq/985859 to your computer and use it in GitHub Desktop.
Solution: The Killer Word(Google Code Jam 2011 Round 1A Problem B)
import sys
from string import ascii_lowercase
# files
fin = file(sys.argv[1])
fout = open(sys.argv[2], 'w')
lines = fin.readlines()
tests = int(lines[0])
# parse
indexes = [1] # of tests in lines
for i in range(tests-1):
nm = lines[indexes[i]].split()
nm = map(int, nm)
nm = sum(nm)
nm = nm + indexes[i] + 1
indexes.append(nm)
def trunc(s0):
return s0.rsplit('\n')[0]
ds = []
seans = []
for i in indexes:
nm = lines[i].split()
nm = map(int, nm)
i0 = i + 1
d = map(trunc, lines[i0:i0+nm[0]])
sean = map(trunc, lines[i0+nm[0]:i0+nm[0]+nm[1]])
ds.append(d)
seans.append(sean)
# hangman
def classify(d0):
sizes = []
for d1 in d0:
try:
i0 = sizes.index(len(d1))
continue
except ValueError:
sizes.append(len(d1))
d2 = []
for size in sizes:
d3 = filter(lambda x:size==len(x), d0)
d2.append(d3)
return d2
l0 = ascii_lowercase.split()
def letters(d0):
l1 = []
for d1 in d0:
for i in range(len(d1)):
try:
i0 = l1.index(d1[i])
continue
except ValueError:
l1.append(d1[i])
# l1.sort()
return l1
for i in range(tests):
da = classify(ds[i])
"""
for j in range(len(seans[i])):
pass
"""
for da0 in da:
la = letters(da0)
print la
"""
Not done with this one, but need a more
'lexically aware' bot to simulate Sean.
Simply looping over every word and guess
will take too long unless use some AI.
Classify dict words based on guess-list
sorted position and frequency and this
could be very fast ;)
Needs custom object to track game state.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment