Write a Hangman Solver
Python: 2006 bytes, score=1501
1885 bytes, score=1337
1961 bytes, score=1207
Here's my submission:
import sys
b='eJwdVQuW4ygMvJdyGgwYtAGJQQKHOf2Wp9/rJqGxVaqP+HxUMlGx5F86/XoqsUuonzAz5cf5vqjJ6OlQudxOJR3ibJ8cwuSmsTX12daVht8ubj15miaEH/GrESXrQrXbl1K0m2hs6dRjMkp1PuS2/9JoVslkLmp2L6J6f5kij4s0nkSPni/5GZtixSuKcKd7lYvsfi7yNYxseKXqV6fURkc//KXe+P6Hc071xuZteixiSRtzMnavwNfqcydqSzb+9hMTlW/UQSNe5uRx1EVp1OhA7gXb0v+i0rKN1rYsGlWBufozlFbzP+i2KXCpNKNjfTwkytcBnv+OgoV6blJ/8NDjF6iqUd2ojqcbrScmIaurHJxs6yHjck96brZJwncsIOHhzwyemZurKFrkmpIX9yXSNGsKdF+F+rF2fam0+KAMj3YdoXFJR+nY7AL4y1jaopNuBhk6sl03pSd7x2IxoyeLO6dGedjp9V0inusji0EAyR4pBttN6dt+UR/SYBHCVwuxPZSvqNYpZhPIWXM3Segs30IFXKZKSzqDkcdORud59xVJ8o4WsJQelUqXnIAjV/2whDybo1mDmhYCeAjZV4552gSWOa5aSG3WZ0SaqZVe4Y+o7R+Ps5knum0pDGNxrKA3De3Lwo/si420aemw2g/tdq5sKN1HyltpLNeY/qPUYwsLatc/pwRq5eSwK4l5LhHEnSIZhhG9xsFqeqDMRctmTnVQRoamwUtloiLNrgV+a0uzHBKAyUYl61yD+m++GkgeW1eiuMDEoCR6504z32V9JHD25tPVHFyXOGOc+A2vABogIw9vfxWBatuHwaWggEELdS+8De8z7ZHhir70cLoQpYYDOgfMw+ASbrhnbrwQ27x4TNt/3qHBEPSmwzlagqlH5J4Bk2FBqEvc9fXORUnnnceiMAc2kALwNdOB4W87eAw2uAwsIncpu+IYutsJwsJ/JfusCZNipqyL8uwjNHuDN3MJQBSg/Sr1ppByfD9RWaAt/QhLGDDv2C1PxSvBbfyEFqNO5ZwZpE2yqd2PjEwueV1aJoBdGxNjSl8klx3nuWAAxgCxKePt0bykLrCcQWspM61K3qcNuJYa53VMBWKNJCsrYkzZGfZf49fotx3ZYURvyYQ+GR6iOVCfT6fB4hkehfOws/k3PjFo82ZgaE60TxccO4DqKEKDVXSsuknSmuzZwB8C+h7YBS3oaRPSyGvurfnNvM2bMustIxXMYsM/WdvAvLn8hIx5CMCJQxEM2P2yLuyWYHvZziC+T8IWooeMVWDnvoF6wcETdOUVYBFcFdCop/CJ07RpwyjNy1kslHYwdfNxGYGtX4lWduETDAFIeLJntoAk/sjHlLI5tIwp6mcLF5gxJOR2eugsO5/fey0EhMb72J+mrwyB3rkw2eT0cCPuAOUc5cw/b7mQi8942Eaig4nkYUE9xi3D+FTVRxd80XLL9MXhgISod0JBHxjPPCNirRsh/0TgWdrB/6u01zHbvUnBDc4yhknZxCXgrgSWdv8h1oQR3q8hjdbbE5zK6e4U9nhNkHxCwjCdN26sS9+BIMPe7+EDExPGccPLQYvC8+SY1ioz3AxVUWfdJi3RNjjEMyiWq31CjITE1cQPTO5En39bkFEzri7c2f8Dkow6qw=='.decode('base64').decode('zlib').split(';')
R=raw_input
def G(c):print c;sys.stdout.flush()
def P(w):
if'END'==w:exit()
d=b[len(w)].split(':');l=len(d[0]);p=f=0
while p<l:
G(d[0][p]);x=R();r=w==x;w=x;f+=r;p+=p+1+r
if'_'not in x:return
for c in d[p-l+1]+'zq':
G(c);x=R();r=w==x;w=x;f+=r
if'_'not in x or f>5:break
while 1:P(R())
Score output:
score is 1501, totalerr is 21608
This program is fully deterministic. The giant blob (which is a base-64-encoded chunk of zlib
compressed data) is a list of decision trees (one tree per word length). Each decision tree encodes a complete binary tree with a depth between 2 and 5. Each internal node is a single character, and the decision proceeds based on whether the character is present or not in the hangman word.
Each leaf node of the binary tree contains an optimized frequency table specific to that branch of the tree search. The table is specifically optimized to favor completion of certain words, while completely ignoring others (which it cannot reach due to the limited "failure" budget). The table isn't optimized to minimize errors, and thus the totalerr count of the program is high despite its (relatively) good score.
The optimizer, which isn't shown, uses a nondeterministic nonlinear optimizer utilizing a randomized gradient descent strategy to produce the frequency tables.
Ruby
A joint submission from user PragTob and myself.
MAX_TURNS = 6
frequencies = {?t=>[3,48,145,214,252,266,249,223,191,142,63,44,16,1,0,1],?h=>[2,14,81,125,85,91,60,42,30,14,11,6,1,1],?e=>[5,49,260,316,456,408,328,279,202,125,50,32,12,0,0,1],?a=>[4,60,211,259,249,266,253,192,152,111,51,42,15,1,0,1],?n=>[4,30,120,136,214,252,238,214,189,128,59,45,16,0,0,1],?d=>[1,25,100,104,131,123,131,81,63,36,14,15,7,1],?f=>[2,13,51,58,64,67,41,40,28,18,11,9,3,1],?o=>[9,44,150,165,195,220,214,168,155,104,46,37,14,1,0,1],?r=>[1,25,140,246,312,310,263,206,150,95,45,32,11,1],?y=>[3,29,41,58,86,94,83,63,52,31,21,12,2],?u=>[2,23,67,117,126,154,107,97,85,48,27,16,2,0,0,1],?b=>[2,22,53,60,72,59,41,30,36,16,7,6,1],?i=>[3,38,143,179,223,299,270,241,205,134,64,44,16,1,0,1],?s=>[3,23,129,176,195,208,177,136,117,71,44,23,13,1],?c=>[0,12,68,122,146,194,180,163,130,85,49,25,7,0,0,1],?l=>[0,18,153,172,190,196,164,131,125,67,35,20,5,0,0,1],?g=>[1,19,42,75,82,104,78,60,39,30,12,10,0,1],?w=>[1,21,56,56,40,41,18,16,6,2,1,0,0,1],?m=>[2,10,77,68,119,94,104,76,68,45,15,17,8,0,0,1],?p=>[1,24,82,84,94,129,105,88,99,56,24,11,7],?k=>[1,6,65,37,28,24,6,10,3,4],?j=>[0,5,5,6,7,6,5,6,2,0,1,1],?x=>[0,6,4,7,15,22,13,16,9,9,2,2],?v=>[0,3,21,39,47,58,63,42,40,23,10,9,2],?z=>[0,0,3,3,3,5,2,3,0,0,1],?q=>[0,0,1,9,5,13,8,3,5,4,3,2]}
while !(input=gets.chomp)['END']
current_turns = MAX_TURNS
won = false
chars = frequencies.keys.sort_by {|c|
-(frequencies[c][input.length-2] || 0)
}
i=0
while (current_turns > 0) && !won
c=chars[i]
i += 1
puts c
$stdout.flush
old_input = input
input = gets.chomp
if input == old_input
current_turns -= 1
# else
# frequencies[c][input.length-2] -= 1
end
won = !input[?_]
end
end
Result:
score is 625, totalerr is 23196
This has 1672 characters and isn't golfed yet so we have ample room for algorithmic improvement.
First we store a hash of character frequencies (computed from the word list) grouped by word length.
Then in each round we simply sort all characters by the frequencies for the current length and try them from most common to least common one. Using this approach we obviously fail every single word that has even just a medium common character.
Update Using method similar to @nneonneo, I arrive to this code, exactly 2047 chars.
Score:
score is 987, totalerr is 21964
Code:
import sys,re
R=raw_input
F=';;;topenayr;elsatrodin;eatslroncih;eastrinclodu;etnocsiralupd;enostciarldpmu;eitnoasrclupmdy;einocstarlpumdyg;itacslnorepumdgyv;intaoslecrupymdgfh;nitaoerclsmudpygfvh;itneaorscmpdlfuvybh;ratdgfihosw;;ceimontalu'.split(';')
G=[''.join('.'*int(c)if i%2 else c for i,c in enumerate(re.split(r'(\d+)',w)))if w else''for w in 'eJwdlA2S4yoMhK+0CpPJ28ppQPxuQFBITMq3f52JXY5TdpC69TXP50ziQ6RWKxV3stBw+XEtIXXvx4u+g5I5e1x0V+fGN236S/b0aU+7UjMNFoyOvVc8hSInersrxBWr0BUqNSchUXT835YlWCyUTtW9Q6PL1UfhRtmVR3gm72dvu/Vts3c+sqPFoSaWbUWqqi9dylLXe65MWM12/CEdkcLX6LVXU7HBuQXSqDyMKTOjgX40Dty966CXY66Q2H/r7b3b7qat2zF8NLbWZ1QpTLvXWN+1NancuPdoE8sXNi1DqrtssxY+7RzRdxUWa5FLDVPzJJnWpTZW4xN4Uay1BFvUIxNKtz2le7/N47Bt3XedKjyttQgl/dhlcfvNZaNkFN8OnsrULiPQGqeeOsZRPZVl+sXsT61413rvqr751pbIBR/CSyWWs+JLrl66li+lM1j2JVDQowzxlUeo451DGDXOnDlD5Dw+7jcrnC855BmvCr8jGpzsa1P/E0VeWqKGwWGtEKVNiodj/4mTRXtgUDQChs4k7UWZ/py7ldsbv5WZ44ugjdj735MDzpFDffPgtQruJdO6vT7rVwYMQa+dCc7xCgVyJ57+65bH6yxj43/D7cxl3vaPAS/YEGfzo/Ess2iINV5To1/5VbMqrXMsV7ZYZJU1KPAZH4rrUNA/pK8MjlCcYAipoCYryaesw1wbD6SFb2+n7YfOZ6xexOb0RZv34Kprn743BtGwYsnZXbadfX3Yw8jAFGtbYGxxc1p08LF4bbbDdYdsvA7wyPUVm3GD70u9t9I9q8oAMUPbaVdV/oXKNwNUIkCCTDyAnd46e21yAyJQFFRn35+G5i97rXeZwuW+tcPYa0VesXNAXzguNviOKGEyEbYjkT56VehF14eRgNYHSjePNnl3L3CAJsMDhNhP072ng0sRvk0Gq0LeMHqRvRUj3/xQNwt3cyBiaEH0we28VZ4LMIse/O34T32sybiAlf1sCXHEzgUNU3wiqOt74zXdqc/pOpXC1UIffoyNUCAjiyfjFb8fehue6hbaPKjXgI4RwIVgBAmXeiC5J5ihGFZKnGAFxLF/WmpxJ6HPtuXTdM1D8m3iWfKPSQFKQPEdmSL/+WA7vItr9JuMKGWsi/7kTrzGLXDoPzvy/jjxq4gMi0E+87xnz7SS+p08EXbM7h32M5QOxRNk3py6TdrHd0kftelzravf4MDBcrCGWvJu4toejG9Ok75SffANw9hp3/6Osegr6L1hfx4YRXoCVUrkXbwFecx74on+P/VTUoewuekqaRrP5/N/1MpqAw=='.decode('base64').decode('zlib').split(';')]
while 1:
w=R();i=0
if'END'==w:break
f=0;l=len(w);g=set()
if G[l]:
while i<len(G[l]):
c=G[l][i];print c;sys.stdout.flush();g.add(c);x=R();i=2*i+2-(w==x);f+=w==x;w=x
if'_'not in x or f>5:i=0;break
if i>=len(G[l]):
for c in F[l]:
if c in g:continue
print c;sys.stdout.flush();x=R();f+=w==x;w=x
if'_'not in x or f>5:break
Old entry
Result:
score is 656, totalerr is 22962
It's not an average since this algorithm is deterministic, i.e., it always gives the same score for any shuffled list of words.
Here is my entry in Python 2.7; golfed (717 characters)
import sys
class S():
def __init__(s):
s.l=6
s.g=set()
s.p=''
F=[0,0,'onastifeybhmudgkprw','topenayridsubwglfhcmkxjv','elsatrodinphmcukwbfgyvjxzq','eatslroncihudpgmfbywvkqxjz','eastrinclodumphygbfvwkxjqz','etnocsiralupdmgyhfbvwkxqjz','enostciarldpmuygvhfbwxqkjz','eitnoasrclupmdyghfvbwxkjqz','einocstarlpumdygvbhfxwqkj','itacslnorepumdgyvfbhxkqw','intaoslecrupymdgfhvbqxjwz','nitaoerclsmudpygfvhbqxj','itneaorscmpdlfuvybh','ratdgfihosw',0,'ceimontalu']
s=S()
while 1:
c=raw_input()
if c=='END':sys.exit()
if '_' not in c:s=S();continue
if c==s.p:s.l-=1
if s.l==0:s=S();continue
s.p=c
for x in F[len(s.p)]:
if x not in s.g:
s.g.add(x)
print x
try:
sys.stdout.flush()
finally:
break
This uses similar idea as @m.buettner, storing an ordered list of letters following which the guesses will be made. But, this does not use frequency data directly, rather, it just tries almost every possible letter permutation and simulate the game, and finally taking the permutation that gives the best score.
This version is optimized using the top-9 letters, so for 2-letter and 3-letter words, the permutation is already the optimal one, in the class of algorithm where the information from previous input is ignored. I'm currently still running the code for top-10 letters, optimizing the 4-letter words (and also finding better solution for longer words).
Invalid entry
For my benchmarking, here is the code that uses the full decision tree, 11092 chars.
Score:
score is 2813, totalerr is 17539
Code:
import sys,re
R=raw_input
F=';;;topenayri;elsatrodin;eatslroncih;eastrinclodu;etnocsiralupd;enostciarldpmu;eitnoasrclupmdy;einocstarlpumdyg;itacslnorepumdgyv;intaoslecrupymdgfh;nitaoerclsmudpygfvh;itneaorscmpdlfuvybh;ratdgfihosw;;ceimontalu'.split(';')
G=[''.join('.'*int(c)if i%2 else c for i,c in enumerate(re.split(r'(\d+)',w)))if w else''for w in 'eJw1momWqyyzhm8pgENc/9UoNGILSoto3Fd/nsq3zt49pBNlKKreAfzf//afbZycWkJQs6l+U8n4/smbKubuV9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iZPkre/5T1wJS9RAnSUdDEa5oBelyN7vOHFIzDTYIfG8Q4s0QuZdpIDKVaGEcqcMs/5p/Qr9okauLOkMXYQCNyWnxrFqwajhorvtyzEAawzlFMl6Ea+5zf+i2ts3noHklyRrNizRhsOAh7rg9/ocKU8uPwMzys/SW3/ZnV81PgGXxIcfPoQd4RjVTaRd5Sgs/+9MOoj+KHr4Phkbt985j8KZUPIYGo00cuGjWFW7J3Pc9jgfDCDAmT/1QBqg7eOfoT0LCLaF331q9sGu9RB63Jfvo8pCIjvOPiz85uWgvW5petswfSZdTmkCmzMjy2k896v5AG11fOSO7GRfuVP/9QoqxzAJ/Txk62UJ5Gu5gaqYbJKn8t0HZBGmLQcCiD0ygUqpsTejs+9Ik4ZtBy3FtQ7X1KrZSf32UXX/YED7spT7sqX7Abaenrd/bHysnFVIaJDF5oI0kePlJHUKgF4g+0L8O2XwMrTzmCqFl9xN/jqaRh2ddK1kJ0Pv4Y99DewyNPKN0RPyIgMp/G2z9IKfWiuV+/ve///0fiWqMOQ=='.decode('base64').decode('zlib').split(';')]
while 1:
w=R();i=0
if'END'==w:break
f=0;l=len(w);g=set()
if G[l]:
while i<len(G[l]):
c=G[l][i];print c;sys.stdout.flush();g.add(c);x=R();i=2*i+2-(w==x);f+=w==x;w=x
if'_'not in x or f>5:i=0;break
if i>=len(G[l]):
for c in F[l]:
if c in g:continue
print c;sys.stdout.flush();x=R();f+=w==x;w=x
if'_'not in x or f>5:break