Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-

★【Challenge!】【Easy】 Hangman Solver

Name: !WIZardrY9E!UhEWzHM7+1tYUG2 2012-05-14 13:16

⚫ The Game of Hangman

A player guesses letters that are part of a word!
If he has not guessed the complete word before making six (6) mistakes, he has lost!

      _______
     |/      |
     |      (_)
     |      \|/   It is a game over!
     |       |
     |      / \
     |
  ___|___


⚫ Your Challenge

In a language of your choice, write a program that takes as its input (in some way) the target word (with blanks) and the letters that have been guessed already. It should then output the next letter to be guessed.
For example:

$ echo -n "p...s\npds" | ./guesser
e

You may assume the word to be guessed is an English word and contains only lowercase ASCII letters.
Provide code and instructions if usage is not obvious. Consider using a tripcode to ease conversation about your entry.

Entries will be judged on GOODITUDE (defined as its win/loss ratio over twenty random games), on SPEED, and on CLEVERNESS.

Your deadline is 23:59:59 on Sunday, May 20th. Results will be posted the following day.

 |∧_∧
 |´・ω・) < Good luck!♫
 ||と ノ

Name: Anonymous 2012-05-14 14:31

Define "an English word".

Name: Anonymous 2012-05-14 14:33

Also this sort of information is best given as two separate entries on the command line.

Name: Anonymous 2012-05-14 14:55

Algorithm:
1. Let I be the (random)th open space in input word
2. Read from file/data provider of 66common99 English words and insert them into a hash map where the hash is the I'th letter of the word
3. Let L be the set of all letters except the ones specified by program argument
4. For every element l in L count the successful matches of every word in entry l of hash map and let the higher count value specify the output letter
5. Return l for higher count value of matches with 66common99 English words

Now implement in C and optimize the matcher function in asm to win challenge

Name: sage 2012-05-14 15:00

>>1
I ain't doing nobody's homework.

>>4
?

Name: Anonymous 2012-05-14 15:17

>>4
Since the program will be invoked once per letter, that's going to be pretty damn slow.

Name: Anonymous 2012-05-14 15:30

>>6
Then drop that requirement

Name: Anonymous 2012-05-14 15:48


from string import *
import random
from hangman_lib import *

secret_word=get_random_word()

congrats=['Magnificient','Stupendous','That was EXPERT Quality','Marveloso','Fantabulous']
snide=['Don\'t worry 2/10 people fail to beat hangman','It\'s a hard game. It\'s not as \
though you have a list of letters you could guess with.','If that was you ,who just got hung,\
you\'d be a hung man. As in asphixiated']

letters_guessed=[]

mistakes_made=0

MAX_GUESSES=8


def randomnum(x):
    return random.randint(1,len(x)-1)

valid='abcdefghijklmnopqrstuvwxyzcheat'


def word_guessed():
    my=[]
    for i in secret_word:
        if i in letters_guessed: my.append(True)
        else: my.append(False)
    return all(my)

   
def print_guessed():
    m=[]
    for i in secret_word:
        if i in letters_guessed:
            m.append(i)
        else: m.append('-')
    print join(m,' ')

##def main():
   
while True:
    print 'You have %d guesses left' % (MAX_GUESSES-mistakes_made)
    print_guessed()
    print letters_guessed
    guess_letter=lower(raw_input('Guess a letter\n'))
    if guess_letter=='cheat':
            print secret_word
    while guess_letter in letters_guessed or guess_letter not in valid:
        guess_letter=lower(raw_input('Letter already picked or invalid input.\
Pick something else.\n'))
       
    letters_guessed.append(guess_letter)
    if guess_letter not in secret_word:
        mistakes_made+=1
        print_hangman_image(mistakes_made)   
    if mistakes_made>=MAX_GUESSES:
        print 'Game over.\n'
        print 'The word was %s' %(secret_word)
        print '%s' %(snide[randomnum(snide)])
        break
    if  word_guessed():
        print '%s ! You did it!\n' %(congrats[randomnum(congrats)])
        print secret_word
        break

print '\nArt created by sk'


Hangman Lib:



def print_hangman_image(mistakes = 6):
  """Prints out a gallows image for hangman. The image printed depends on
the number of mistakes (0-6)."""
 
  if mistakes <= 0:
    print''' ____________________
| .__________________|
| | / /    
| |/ / 
| | /    
| |/  
| |    
| |  
| |   
| |    
| |   
| |  
| |  
| |   
| |     
| |     
| |      
| |     
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''

  elif mistakes == 1:
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |       
| |    
| |   
| |  
| |  
| |   
| |     
| |     
| |      
| |     
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''
  elif mistakes == 2:
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |          -`--'
| |          |. .| 
| |          |   |  
| |          | . |   
| |          |   |    
| |          || ||
| |     
| |     
| |      
| |     
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''
  elif mistakes == 3:
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |         .-`--'
| |        /Y . .|
| |       // |   | 
| |      //  | . |  
| |     ')   |   |    
| |          || ||
| |     
| |     
| |      
| |     
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''
  elif mistakes == 4:
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |         .-`--'.
| |        /Y . . Y\\
| |       // |   | \\\\
| |      //  | . |  \\\\
| |     ')   |   |   (`
| |          || ||
| |     
| |     
| |      
| |     
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''
  elif mistakes == 5:
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |         .-`--'.
| |        /Y . . Y\\
| |       // |   | \\\\
| |      //  | . |  \\\\
| |     ')   |   |   (`
| |          ||'||
| |          ||  
| |          ||  
| |          ||  
| |         / | 
""""""""""""""""""""""""|
|"|"""""""""""""""""""|"|
| |                   | |
: :                   : :
. .                   . .'''
  else: #mistakes >= 6
    print''' ___________.._______
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \\
| |          ||  `/,|
| |          (\\\\`_.'
| |         .-`--'.
| |        /Y . . Y\\
| |       // |   | \\\\
| |      //  | . |  \\\\
| |     ')   |   |   (`
| |          ||'||
| |          || ||
| |          || ||
| |          || ||
| |         / | | \\
""""""""""|_`-' `-' |"""|
|"|"""""""\ \       '"|"|
| |        \ \        | |
: :         \ \       : :
. .          `'       . .'''

import random
def get_random_word():
  """Returns a random word from the file word_list.txt in the same directory"""
  input_file = open('word_list.txt','r')
  word_list = [word.strip().lower() for word in input_file.readlines() if word.strip().isalpha() and len(word) > 4]
  input_file.close()
 
  return word_list[random.randint(0,len(word_list)-1)]


Words list:

Name: Anonymous 2012-05-14 15:48

Name: Anonymous 2012-05-14 16:11

>>4
C is fucking shit.

Name: Anonymous 2012-05-14 16:39

>>10

0/10, cancer

Name: Anonymous 2012-05-14 16:46

>>11
-inf, faggotry. C is undefined shit; x86 assembly is KING!

Name: Anonymous 2012-05-14 16:50

>>12

0/10, cancer

Name: Anonymous 2012-05-14 16:54

>>13
fuck off and die you cock sucking faggot

Name: Anonymous 2012-05-14 16:57

>>14
0/10, cancer

Name: Anonymous 2012-05-14 17:03

>>15
fuck off and die you cock sucking faggot

Name: Anonymous 2012-05-14 17:30

>>15
0/10, cancer

Name: Anonymous 2012-05-14 17:31

>>17
FUCK OFF AND DIE IN A FUCKING FIRE YOU FUCKING COCK SUCKING FAGGOT

Name: Anonymous 2012-05-14 17:32

>>18
0/10, cancer

Name: Anonymous 2012-05-14 17:54

>>8-9
Did you post this so we could test our entries, or because you didn't read >>1 properly?

>>10-19
SPAWHBTC. The first honest challenge thread in like a year and this is how you behave?

Name: Anonymous 2012-05-14 17:54

>>20
Fuck you cock sucking faggot

Name: Anonymous 2012-05-14 18:01

>>21
0/10, cancer

Name: Anonymous 2012-05-14 18:08

>>22
nice doubles

Name: Anonymous 2012-05-14 19:49

Here's a Ruby solution:

WORDLIST = 'words.txt' # Make this something else.
hints, guesses = $*
regex = /^#{hints.gsub('.', '(.)')}$/

letters = Hash.new(0)
open(WORDLIST).each_line do |w|
  w.chomp.match(regex) do |m|
    m.captures.each do |c|
      letters[c] += 1
    end
  end
end

letters = letters.sort_by { |k, v| v }
letters.reject! { |k, v| guesses.include? k }
puts "Guessing: #{letters[-1][0]}."


Usage:

$ ruby hangman.rb p.ncre.s epsrcn
Guessing: a.
$ ruby hangman.rb kangar.. argnk
Guessing: o.


It's not optimzed for anything at all, but it is short.

Name: Anonymous 2012-05-14 22:53


#!/usr/bin/python

from hangmanlib import hangman

hangman()


hangmanlib implementation is left as an exercise to the ``reader".

Name: Anonymous 2012-05-15 8:40

>>25
rofl 10/10 bud I came onto my pizza

Name: Anonymous 2012-05-15 10:22

>>26
xD

Name: Anonymous 2012-05-15 12:53

Bampu pantsu.

Name: Anonymous 2012-05-15 13:01

Business solutions.

Name: Anonymous 2012-05-15 14:54

module Main where

import Data.List (sortBy)
import Data.List.Split (wordsBy)
import Data.Char (isSpace)
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Text.Read as T
import qualified Data.Text.IO as T

type PList = [(Char, Double)]
type LUT = M.Map String PList

sortPList :: PList -> PList
sortPList = sortBy (\x y -> snd y `compare` snd x)

filterPList :: String -> PList -> PList
filterPList s l = filter (\(x, y) -> not $ x `elem` s) l

splitFreqs :: Int -> [[a]] -> ([a], [[a]])
splitFreqs _ [] = ([], [])
splitFreqs l (x:xs)
    | length x == l+1 = (p, x:pp)
    | length x == l = if null p then (x, pp) else next
    | otherwise = next
    where next@(p, pp) = splitFreqs l xs

mkPMap :: [T.Text] -> (String, [Double])
mkPMap (x:xs) = (T.unpack x, case dbls of
                                 Just d -> d
                                 _ -> [])
    where dbls = mapM toDbl xs
          toDbl :: T.Text -> Maybe Double
          toDbl t = case T.double t of
                        Right (d, t') -> if T.null t' then Just d else Nothing
                        _ -> Nothing

mkFreqLookup :: T.Text -> (PList, LUT, Int)
mkFreqLookup bs = (p', pp'', maximum $ map (length . fst) pp')
    where nonnull = filter (not . T.null) $ T.lines bs
          ll = filter (\x -> T.head x /= '#') nonnull
          key' = filter (not . isSpace) $ T.unpack (head ll)
          key = map (\x -> if x == 'S' then ' ' else x) key'
          (p, pp) = splitFreqs (length key) (map T.words $ tail ll)
          p' = sortPList $ zip key (snd $ mkPMap (T.empty : p))
          pp' = map (\(x, y) -> (x, zip key y)) $ map mkPMap pp
          pp'' = M.fromList pp'

words' :: String -> [String]
words' s = if last s == '.' then w else init w
    where w = wordsBy (== '.') s

findWordProbs :: Int -> LUT -> String -> PList
findWordProbs 0 _ _ = []
findWordProbs m lut s = case f of
                            Just i -> i
                            _ -> findWordProbs (l-1) lut s
    where l = min (length s) m
          f = M.lookup (reverse $ take l $ reverse s) lut

main = do
    fc <- T.readFile "freqlist"
    w <- getLine
    used <- getLine

    let (guess, lut, match) = mkFreqLookup fc
        w' = words' w
        plists = concatMap (findWordProbs match lut) w'
        probs = sortPList $ filterPList used plists
        next = if null probs
                   then fst $ head $ filterPList used guess
                   else fst $ head probs

    putStrLn [next]


freqlist: http://pastebin.com/wFzSJxen

Quick and dirty. Uses frequency analysis to determine the next best guess

Name: Anonymous 2012-05-15 15:21

I agree with >>7 , you should just run the program once and give it words through stdin.

Name: Anonymous 2012-05-15 16:58

>>31
std in my anus

Name: Anonymous 2012-05-15 17:03

>>31
It's almost as if considering trade-offs between reading an entire dictionary every time and using one-size-fits-all frequency tables is part of the challenge.

Name: Anonymous 2012-05-15 17:24

i like that vip cat thing. what is it called

Name: Anonymous 2012-05-15 17:33

IT'S CALLED "PLUG AND PLAY DETECTED AN ERROR FAULT EXPCSEXTION! WONT LET U INSTAL WINBLOWS UNLESS U UNPLUG UR EXTERNAL HDD!!!"

PLUG AND PLAY MY ANUS LOL!

Name: Anonymous 2012-05-15 17:40

>>35
oh and i am the proud ofner of a external hdd that makes windows BSOD instantly when I plug it in an USB port, (YES even when autoplay/autorun disabled)

isn't that awesome? Y/N

Name: Anonymous 2012-05-15 20:55

import sys
import random
#two arguments needed
if(len(sys.argv) != 2):
    print "Usage: n"
    print "n - word to finish guessing"
else:
    #get the guess
    guess = sys.argv[1]
    #to match the word
    def match(word):
        #get rid of extra whitespace!
        word = word.strip()
        #if the guess and the word have equal length
        if(len(word) == len(guess)):
            #for every character in both the guess and the word
            for i in range(len(guess)):
                #if the guess was made and the guess was incorrect
                if(guess[i] != '.' and guess[i] != word[i]):
                    #no match
                    return False
            #all guesses ok or not made - matches
            return True
        else:
            #no length match - no match
            return False
    #get all matching words from the word list
    l = filter(match, open("words.txt", "r"))
    #if we have matching words
    if(len(l) != 0):
        #get a list of all the un-made guess characters
        a = []
        for i in range(len(guess)):
            if(guess[i] == '.'):
                a.append(i)
        #pick a random word out of the word list, and then pick one of its random letters that corresponds to a un-made guess - BAD
        random.seed()
        print l[random.randint(0, len(l) - 1)][a[random.randint(0, len(a) - 1)]]

heres my shitty entry. didn't think much about how to actually pick what word to guess though.....

dictionary should be called words.txt and should be in same directory as this script. dictionary format should just be 1 word (lowercase) per line - used the lower case corncob list for testing
http://www.mieliestronk.com/wordlist.html

Name: Anonymous 2012-05-15 20:57

>>37
also, no checking asides from # of cmd line args
:(

Name: Anonymous 2012-05-15 20:59

Code tags exist for a reason.

Name: Anonymous 2012-05-15 21:07


>>39
sorryyyyyyyyy

import sys
import random
#two arguments needed
if(len(sys.argv) != 2):
    print "Usage: n"
    print "n - word to finish guessing"
else:
    #get the guess
    guess = sys.argv[1]
    #to match the word
    def match(word):
        #get rid of extra whitespace!
        word = word.strip()
        #if the guess and the word have equal length
        if(len(word) == len(guess)):
            #for every character in both the guess and the word
            for i in range(len(guess)):
                #if the guess was made and the guess was incorrect
                if(guess[i] != '.' and guess[i] != word[i]):
                    #no match
                    return False
            #all guesses ok or not made - matches
            return True
        else:
            #no length match - no match
            return False
    #get all matching words from the word list
    l = filter(match, open("words.txt", "r"))
    #if we have matching words
    if(len(l) != 0):
        #get a list of all the un-made guess characters
        a = []
        for i in range(len(guess)):
            if(guess[i] == '.'):
                a.append(i)
        #pick a random word out of the word list, and then pick one of its random letters that corresponds to a un-made guess - BAD
        random.seed()
        print l[random.randint(0, len(l) - 1)][a[random.randint(0, len(a) - 1)]]

Name: Anonymous 2012-05-15 21:07

>>39
Maybe >>37-kun is Andrew S. Tanenbaum. You don't know.

Name: Anonymous 2012-05-15 23:46

This challenge is fucking dumb.

Name: Anonymous 2012-05-16 10:59

>>42
Your face is fucking dumb.

Name: Anonymous 2012-05-16 11:48

>>41
But Andrew S. Tanenbaum deserves more animosity from the systems programming community and beyond than anyone

Name: Anonymous 2012-05-16 11:59

>>44
why?

Name: Anonymous 2012-05-16 13:52

>>45
Modern Operating Systems, 3rd edition - Andrew S. Tanenbaum
By reading it, you will learn to hate him. In part due to his pandering to the Uni money-grubbing book market, by inflating every sentence to fill a fucking page; mostly however, because he's stuck in the '90s and refuses to acknowledge that a micro kernel isn't THE ONE TRUE WAY IN 100% OF CASES

Name: Anonymous 2012-05-16 17:19

>>46
actually it is, it's just that he doesn't realizes that C is fucking shit.

Name: Anonymous 2012-05-16 18:25

>>46
money-grubbing
Jealous, dumb goy?

Name: Anonymous 2012-05-16 19:15

>>40
I'm sorry to have to say this, but your code fucking sucks; also you don't have to comment every single line.

Name: Anonymous 2012-05-16 19:55

>>30
This doesn't seem to work.

$ echo -e "kangar..\nargnk" | ./hangman
hangman: Prelude.maximum: empty list
$ echo -e "p.ncre.s\nepsrcn" | ./hangman
hangman: Prelude.maximum: empty list

May just be the fact that I'm using GHC 6.12.1, though. I don't know enough Haskell anymore to tell.

Name: Anonymous 2012-05-16 20:03

>>37,40
You really need to take guessed letters into account. If the word isn't in your word list, it will guess wrong letters forever instead of eventually working its way to right ones.

Name: Anonymous 2012-05-16 20:08

>>49
It's a beginner's challenge. Be nice or constructive.

Name: Anonymous 2012-05-17 0:50

>>51
b-b-b-b-bbbbut how can we know what letters were already guessed if we only get the guess as input?
>>49
ss-s-s-sorrrry anon-kun, i will do better next time!

Name: Anonymous 2012-05-17 1:10

>>53
OH NO
I DIDN'T READ
ahhhhh
sorry anon-kun. im slow. forgive me!

Name: Anonymous 2012-05-17 9:19

>>50
I think you're missing the freqlist file

Name: Anonymous 2012-05-17 11:00

>>55
No, then it would say this:

hangman: freqlist: openFile: does not exist (No such file or directory)

Name: Anonymous 2012-05-17 17:35

>>56
I only know what GHC 7.0 complains about. I could imagine a readFile function that would just return empty if the file didn't exist. But yes, I did write it with GHC 7.0.4 and I honestly don't know enough about haskell to know how to fix it.

Name: Anonymous 2012-05-17 18:01

>>57
I upgraded to GHC 7.4.1 (the most recent version), and it's still doing the same thing as in >>50. Are you sure it works for you?

Name: Anonymous 2012-05-17 18:49

>>58
Just copied it from here and pastebin and it works fine.
$ echo -e "p.ncre.s\nepsrcn" | ./hangman
a

Maybe the freqlist file is improperly formatted on your end?

The first non-empty non-comment line is supposed to be the letters a-z with spaces. Followed by a line of 26 fp numbers, followed by a lot of lines like this:
a   0.0002835 0.0228302 0.0369041 0.0426290 0.0012216 0.0075739 0.0171385 0.0014659 0.0372661 0.0002353 0.0110124 0.0778259 0.0260757 0.2145354 0.0005459 0.0195213 0.0001749 0.1104770 0.0934290 0.1317960 0.0098029 0.0306574 0.0088799 0.0009562 0.0233701 0.0018701
where the first column is the prefix

Name: Anonymous 2012-05-17 18:53

>>59
I removed the commented and empty lines at the start of the freqlist file, and now it seems to work. I don't know why that should matter if it doesn't on your end, but I guess the important thing is that it works now.

Name: Anonymous 2012-05-17 19:43

>>60
You know what, I bet you're on OSX. I just tried with classic Mac line endings (ie. '\r') and Windows (ie. "\r\n") and got the same error. It's probably getting the '\r' in each line and misinterpreting it as a key character.

Name: Anonymous 2012-05-17 20:01

>>61
Nope, Linux here.
I did wget the file rather than copy/paste it, so I thought I might have gotten bad line endings that way because that's happened before, but apparently not.

              ∧_∧     
      ∧_∧    (´<_`  ) ∠ It's a mystery
     ( ´_ゝ`)    /  ⌒i  
 ̄\  /   / ̄ ̄ ̄ ̄ ̄/. |    
 ̄ ̄| /   ./         /. | |
 ̄| |(__ニつ/_____/_| |____
田| | \___))\    (u ⊃
ノ||| |       ⌒ ̄


Oh well, it works now.

Name: Anonymous 2012-05-18 15:27

Bampu pantsu. I see /prog/ is shitflooding again.

Name: Anonymous 2012-05-18 15:41

>>63
fuck you nigger I'm going to shitbump ever shitpost in the last 20 years

Name: Anonymous 2012-05-18 15:45

                           __, R,
                        f '/ Y ^ `┐ pieces _ ~I
                    _, Ino i / / ∧ヽ
                ー= off '_ input / - ─ ┴亠-, / ^ Isuzu,
                     / / / /'' ¯ ¯ l (c) `T -` _-, vinegar,
                  ヽpcs / / / / ∧ _ "J ij i`ヽsystem!!!!
                   / '|!! / / Haruna x re Buddha Ii l / l re
                ! {i Centro Do弌ヽapplication / ~I chair Te, ij |
                       Doヾthe / / / f ∧ re `i_ ji ::: ::::": |
                  / / :/ / c "" '`''' boards Roh l
                   / / :/ / / \ `'│ c" do a
               ¯ \ \ / / jl _ Doヽ, ~I. '| | ii
                - |} \ / (c) s nailゝ¯ `ーDo ~A | il
               /ヽ, _ /: / / :::::ヽ/ | ::::::> I | | '¯ `┐
                / / :: =:.! l │ :: - / /, | / :::: l ¯>
             / c ::: l ::::: {::::ヽ/ / J I-─ -: | l __ / ∧
            .!! / f {::::::: l i l :: re :: _ ::: <__ ~I> :::: 〃> He N.!
            〃 :::: f f =: i ii i i c I was ::::: :::::: /! ! ⌒ / ::::::: | Ha
             Ha l_ ∠ │ :::: 〃 Explosion 〃 butterfly i ii i / 8 / c `ーre :: :::::::::: i │! :> │ヾ
           to i │ヽ/ {c L__ i_i_ module j re f ::: ::::: ___ :: boards :: Roh ~I Lee |ヽ!.
            re | _ / \ ____ {=ヽ= `ー-} /ヽt"ヾ> I
           , '"/ I {ヽ- i /乂} /ヽ___
          ! / Lee r '- _} "i ∧ ∨ー
      , '"/ vector r-ya __ヽ_ -. tt ∧ヽ,
. Roh '¯ ¯, - ¬ - <'' ::: {Chi}ヽ\ `ー─' 'ヽ, 〃 / {=} <
two being '/ ::: :::::::::::::::::: {≠} \ / {switch} \ ::::ヽ, _ヽ- two knee ┐ '"
::::ヽf: ¯ ¯ :::::::::::::::::::: / :/ {∠}ヽ/ {∠} :::::: \ :::::::: `ー=, Le `f
c ::::: \ :::::::::::::::::::::: / :::: / :: <- Explosion {/ /> :::ヽ:::::::: ::::::::::::::::::::::ヽ- Lee seven ::::>
:::: :::: ∧ ::: \ ::::::::::::::::::::::: / :::::: Mu / / I f ≧} ::::::::: :::::::::::::::::::::::: / ::::::::::: / off ::::
::::::::ヽ:::::::::::::::::::::::::::::: / ::::::::::: The example `_ / eyes Do f ::::: :::::::::::::::::::::::::::::::::::::::::::: / :::: ∧
:::::::::::ヽ:::::::::::::::::::::::::::::::: ::::::: / :::: '/ ::::::::::: :::::::::::::::::::: Ha勹ヽ弌ヽ::::::::::::::::::: / ::::::: | f
::::::::::::::ヽ:::::: :::::::::::::::::::::::::: / :::::::::: \ ∨ f ┬ __, Kim 's / :::: Ha ::::::::::: :::::::::::::::::::::::::::::::::: / ::: :::::: |. _ system
\ :::::::::::: Ha :::::::::::::::::::::::::: Weゝ::::::::::::::::::: _ `:/ヾHim '" ::::::::::::::::::::: : Ha :::::::::::::::::::::::::::: / ::::::::::: | /

Name: Anonymous 2012-05-18 15:53

>>64
good l,uck bumping eVERY SINGLE POST in the HISTORY OF 4CHAN

Name: Anonymous 2012-05-18 16:02

>>66
AuTIsM is the disease, and DUBZ are the cure

Name: Anonymous 2012-05-18 16:05

no, rought peneratritooN Slave Bdsm harcode Bondage would be teh ecureurCuu
No wait, there is no cure.

Name: Anonymous 2012-05-18 16:13

>>68
yo'uRe wrog,n dubz aRE THE CURE!!!!1

Name: Anonymous 2012-05-18 16:21

>>69
ok butt why do you talk in AlTerNATE CapZ?

Name: Anonymous 2012-05-18 16:27

>>70
I am nOt comPLEtely cure.d

Name: Anonymous 2012-05-19 10:32

Bomp. Deadline is tomorrow and we've only had three entries.

Name: VIPPER 2012-05-19 10:39

>>72
Thanks for remind me, i wanted to send in a cheap one lol.
But i forgot about continuing working on it.

Name: Anonymous 2012-05-19 16:36

new entry. anon-kun, is this suitable?

import sys
validwords = filter(lambda tuplist : len(filter(lambda tup : tup[0] == '.' or tup[0] == tup[1], tuplist)) == len(tuplist), map(lambda word : zip(sys.argv[1], word), filter(lambda word : len(word) == len(sys.argv[1]), map(lambda word : word.strip(), open("words.txt", "r")))))
letters = {}
for word in validwords:
    used = []
    for guess, letter in word:
        if letter in letters:
            letters[letter] += 1
        else:
            letters[letter] = 1
if(len(sys.argv) == 3):
    letters = dict((k, v) for k,v in letters.iteritems() if k not in sys.argv[2])
chosen = max(letters.iterkeys(), key=lambda k : letters[k] )
print chosen

sytnax - python <script name> <guess> <guessed letters in a list ie abcde>
use . to indicate unguessed letters
also, this fails if the word isn't in the word list
word list format is just 1 word per line in "words.txt" in the same directory as the script

Name: Anonymous 2012-05-19 16:37

and i forgot to remove used = [] :(((((((((
crap, anon-kun, i always screw up somehow

import sys
validwords = filter(lambda tuplist : len(filter(lambda tup : tup[0] == '.' or tup[0] == tup[1], tuplist)) == len(tuplist), map(lambda word : zip(sys.argv[1], word), filter(lambda word : len(word) == len(sys.argv[1]), map(lambda word : word.strip(), open("words.txt", "r")))))
letters = {}
for word in validwords:
    for guess, letter in word:
        if letter in letters:
            letters[letter] += 1
        else:
            letters[letter] = 1
if(len(sys.argv) == 3):
    letters = dict((k, v) for k,v in letters.iteritems() if k not in sys.argv[2])
chosen = max(letters.iterkeys(), key=lambda k : letters[k] )
print chosen

Name: Anonymous 2012-05-19 21:55

Against random words the best strategy is to maximize your expected chance of winning, but because the game tree grows exponentially you can't brute force every possibility and have to use a heuristic. ``Most used character'' is a very good heuristic, and ``most entropy in result for this turn'' is also pretty good but harder to compute. How many of the top heuristic choices to examine is a trade-off, but because of diminishing returns I like 2. Perhaps a dynamic choice would be best.

On another note, don't forget to filter out words that have characters that have already been guessed and found not be in the word.

#lang racket/base

;; Usage: racket -t hangman.rkt [word misses]
;; Input is taken from stdin if not given on command line

(define word-list "corncob_lowercase.txt")
(define lives 6)
(define search-width 2)

(require racket/file racket/set srfi/1 srfi/13 racket/flonum)

(define argv (current-command-line-arguments))
(when (zero? (vector-length argv)) (set! argv (vector (read-line) (read-line))))

(define (number-of-words-containing c words)
  (count (lambda (word) (string-index word c)) words))
(define (string->seteqv s) (for/seteqv ((c (in-string s))) c))

(define word (vector-ref argv 0))
(define misses (vector-ref argv 1))
(define acceptable?
  (let ((r (regexp (format "^~a$" (if (string-null? misses) word (regexp-replace* "\\." word (format "[^~a]" misses)))))))
    (lambda (word) (regexp-match? r word))))
(define cur-words (filter acceptable? (file->lines word-list)))
(define full-alphabet (string->seteqv "abcdefghijklmnopqrstuvwxyz"))
(define cur-alphabet (set-subtract full-alphabet (string->seteqv word) (string->seteqv misses)))

(define (best alphabet words lives)
  (define (wins c)
    (define next-alphabet (set-remove alphabet c))
    (define rx (regexp (regexp-quote (string c))))
    (define h (make-hash))
    (for-each (lambda (word) (hash-update! h (regexp-match-positions* rx word) (lambda (v) (cons word v)) '())) words)
    (define (group-wins k v)
      (define next-lives (if (null? k) (- lives 1) lives))
      (let-values (((_ w) (best next-alphabet v next-lives))) w))
    (define (total-wins) (apply + (hash-map h group-wins)))
    (cond
      ((and (= (hash-count h) 1) (null? (car (hash-keys h))))
       0)
      (else
       (total-wins))))
  (define n (length words))
  (define in-all
    (do ((a alphabet (set-intersect a (string->seteqv (car ws))))
         (ws words (cdr ws)))
      ((or (set-empty? a) (null? ws)) a)))
  (cond
    ((zero? lives)
     (values #f 0))
    ((= n 0)
     (error "That's not possible."))
    ((= n 1)
     (define letters-left (set-intersect alphabet (string->seteqv (car words))))
     (if (set-empty? letters-left)
         (values #f 1)
         (values (car (set->list letters-left)) 1)))
    ((not (set-empty? in-all))
     (define c (car (set->list in-all)))
     (define c-wins (wins c))
     (values c c-wins))
    (else
     (define choices (set->list alphabet))
     (define sorted-choices (sort choices > #:key (lambda (c) (number-of-words-containing c words))))
     (define choices-to-examine (take sorted-choices search-width))
     (let loop ((l choices-to-examine) (best-c #f) (best-wins 0))
       (cond
         ((null? l)
          (values best-c best-wins))
         (else
          (define c (car l))
          (define c-wins (wins c))
          (cond
            ((= c-wins n)
             (values c c-wins))
            ((> c-wins best-wins)
             (loop (cdr l) c c-wins))
            (else
             (loop (cdr l) best-c best-wins)))))))))

(let-values (((c w) (best cur-alphabet cur-words (- lives (string-length misses)))))
  ; (printf "Best choice is \"~a\", winning ~a out of ~a times (~a%)\n" c w (length cur-words) (fl* (fl/ (exact->inexact w) (exact->inexact (length cur-words))) 100.))
  (printf "~a\n" c))

Name: Anonymous 2012-05-20 5:12

dubz. slick 'em, flick 'em, stick 'em, pick 'em, click 'em.

Name: Anonymous 2012-05-20 6:54

When a problem comes along you must whip it.

Name: VIPPER 2012-05-20 16:49

(use-modules (ice-9 rdelim))

(define Hang 0)
(define Len 1)
(define File "hangman.txt")
(define Char 0)

(define Handle
        (open-input-file File))
(define Word
        (read-line Handle)); For time reasons i put one word in here :/
; Thought of making it read lines in a loop and the test being a random number of some sort with the last read line being the word
(while (and (if (= Hang 6)
                (begin (display "LOST!\n") ; I wish i had time to make it draw a hanging man but i dont have it
                       #f))
            (not (= (string-length Word)
                    Len)))
       (set! Char
             (read-char (current-input-port)))
       (if (not (char=? Char #\nl)) ; Filter #\nl(\n) read when pressing enter
           (if (not (char=? Char (string-ref Word
                                             Len)))
               (set! Hang
                     (+ 1 Hang))
               (begin (set! Len
                            (+ 1 Len))
                      (display Char))))

A very simple and primitive implementation
Im made this sort of in a real rush, but i send it in anyway.
I wish i had the time to improve it.

Dont be hard on me since this is my first real scheme program.
It should work, i couldnt test i as much as i should.

Im glad OP took the time to make a programming contest, i missed those.

Name: Anonymous 2012-05-20 20:10

>>79
I hate to break this to you, VIPPER-kun, but that wasn't what was asked.

Name: Anonymous 2012-05-20 20:14

>>79
Go fuck an autistic retard.

Name: VIPPER 2012-05-21 3:51

>>80
Damnit! Now that you mention it, my program is useless as fuck.

FUCK

Name: Anonymous 2012-05-21 3:59

You shame the VIPPER name.

Name: VIPPER 2012-05-21 4:16

>>83
Yeah, maybe i should shame the Anonymous name instead.

Name: !WIZardrY9E!UhEWzHM7+1tYUG2 2012-05-21 6:54

FINI

Thank you for your contributions!
I have examined >>24, >>30, >>40, >>75, and >>76, and these are my judgments:


GOODITUDE and also SPEED

These categories were assessed automagically, using http://sprunge.us/jdfY?py and a pregenerated list of twenty words. This yielded http://sprunge.us/WhiM.

The winner in the category of GOODITUDE is therefore >>75-san. Congratulations, >>75-san!
And the winner in the category of SPEED is clearly >>30-san. Congratulations, >>30-san!


CLEVERNESS

This category was judged subjectively and capriciously.
None of the entries did anything particularly unexpected, therefore I am going to award this category to >>24-san, for being the shortest while still being quite respectful in the other categories. Congratulations, >>24-san!


Winners may collect their Sußcoins at the front desk. Non-winners are invited to try again next time (and so are winners)!

'-._                  ___.....___
    `.__           ,-'        ,-.`-,            THANK YOU
        `''-------'          ( p )  `._       FOR PLAYING
                              `-'      \     
                                        \
                              .         \
                               \---..,--'
   ................._           --...--,
                     `-.._         _.-'
                          `'-----''

Name: Anonymous 2012-05-21 16:09

All play and no work makes Jack a wise man.

Name: Anonymous 2012-05-22 22:32

Bump, because I don't think anyone saw the results.

Name: Anonymous 2012-05-23 0:29

Now that the contest is over, this is now a general Hangman solver thread. Post your shit code.

Name: Anonymous 2012-05-23 3:56

here have a mountain of scheme


(define (unordered-filter predicate lis)
  (letrec ((loop (lambda (lis acc)
                   (cond ((null? lis)
                          acc)
                         ((predicate (car lis))
                          (loop (cdr lis) (cons (car lis) acc)))
                         (else
                          (loop (cdr lis) acc))))))
   (loop lis '())))

(define (all? pred lis)
  (cond ((null? lis) #t)
        ((pred (car lis)) (all? pred (cdr lis)))
        (else #f)))

(define (range i j)
  (letrec ((loop (lambda (j acc)
                   (if (<= i j)
                     (loop (- j 1) (cons j acc))
                     acc))))
   (loop j '())))

(define (char-range a b)
  (map integer->char (range (char->integer a) (char->integer b))))

;; evaluates functions on a fixed input.
(define (evaluator x)
  (lambda (f)
    (f x)))

;; checks if a guess will match a fixed word.
(define (checker word)
  (lambda (guess)
    (equal? guess word)))

;; collects all indeces in which the letter matches a fixed word.
(define (matching-index-collector word)
  (lambda (letter)
    (letrec ((loop (lambda (i matches)
                     (cond ((>= i (string-length word))
                            matches)
                           ((equal? (string-ref word i) letter)
                            (loop (+ i 1) (cons i matches)))
                           (else
                            (loop (+ i 1) matches))))))
     (loop 0 '()))))

;; Sees how many times a letter will match a fixed word.
(define (scorer word)
  (lambda (letter)
    (letrec ((loop (lambda (i score)
                     (cond ((>= i (string-length word))
                            score)
                           ((equal? (string-ref word i) letter)
                            (loop (+ i 1) (+ score 1)))
                           (else
                            (loop (+ i 1) score))))))
     (loop 0 0))))

;; Sums the scores for a letter, recieved from a fixed list of scorers.
(define (sum-scorer scorers-list)
  (lambda (letter)
    (apply + (map (evaluator letter) scorers-list))))


;; evaluates to the element in domain-list that maximizes f.
(define (arg-max domain-list f)
  (letrec ((loop (lambda (current-arg-max current-max domain-list)
                   (if (null? domain-list)
                     current-arg-max
                     (let* ((next-arg (car domain-list))
                            (next-value (f next-arg)))
                       (if (> next-value current-max)
                         (loop next-arg next-value (cdr domain-list))
                         (loop current-arg-max current-max (cdr domain-list))))))))
   (loop (car domain-list) (f (car domain-list)) (cdr domain-list))))

(define (hang-man words-list goal-checker goal-matching-index-collector goal-length lives)
  (let ((chopped-words-list (unordered-filter (lambda (str) (= (string-length str) goal-length)) words-list)))))

;; returns (words-list missing-letters-list lives-count)
(define (hang-man-loop words-list goal-matching-index-collector missing-letters-list lives-count)
  (if (or (= lives-count 0) ;; dead
          (null? words-list) ;; word wasn't valid
          (null? missing-letters-list) ;; word contained unknown letters
          (null? (cdr words-list))) ;; got it down to one word!
    (list words-list missing-letters-list lives-count)
    (let* ((best-letter (arg-max missing-letters-list (sum-scorer (map scorer words-list))))
           (remaining-letters (unordered-filter (lambda (letter) (not (equal? letter best-letter)))
                                                missing-letters-list))
           (matching-indeces (goal-matching-index-collector best-letter)))
     (if (null? matching-indeces)
       (hang-man-loop words-list goal-matching-index-collector remaining-letters (- lives-count 1))
       (let ((remaining-words (unordered-filter (lambda (word)
                                                  (all? (lambda (index)
                                                          (and (< index (string-length word))
                                                               (equal? (string-ref word index) best-letter)))
                                                        matching-indeces))
                                                words-list)))
         (hang-man-loop remaining-words goal-matching-index-collector remaining-letters lives-count))))))


(define (hang-man words-list goal-matching-index-collector goal-string-length alphabet lives-count)
  (hang-man-loop (unordered-filter (lambda (str) (= (string-length str) goal-string-length)) words-list)
                 goal-matching-index-collector
                 alphabet
                 lives-count))


(define alphabet (map integer->char (range 0 255)))

(define goal-word (read))

(define words-list (read))

(define lives-count (read))

(define result (hang-man words-list (matching-index-collector goal-word) (string-length goal-word) alphabet lives-count))

(display result) (newline)


give it:

"goal word"
("dictionary" "list" ...)
lives-count

as input, and it'll:
1. pick an unchosen letter that would yield the largest sum of discoveries in all considerable words left in the dictionary.
2. find all positions where the letter matches the goal word.
3. filter the dictionary with words that match the chosen letter, in the same positions.

It seems alright, but consider it SLOW AS FUCK

Name: Anonymous 2012-05-23 4:03

>>89
(       (                              )
  (       ((     (       (       )
                   (     ((         )
                             )
                         ((          (       ))
                          (     (       ) (     (       )    )))
                         (   
                          (     (       )    ))))))
   (          ())))

(       (             )
  (     ((         )   )
        ((     (       )) (          (       )))
        (       )))

(       (         )
  (       ((     (       (     )
                   (   (      )
                     (     (     ) (          ))
                        ))))
   (        ())))

(       (              )
  (                  (      (               ) (               ))))

                                       
(       (           )
  (       ( )
    (   )))

                                            
(       (            )
  (       (     )
    (                 )))

                                                                
(       (                             )
  (       (      )
    (       ((     (       (         )
                     (     ((     (                  ))
                                   )
                           ((       (                 )       )
                            (     (     ) (              )))
                           (   
                            (     (     )        ))))))
     (        ()))))

                                                       
(       (           )
  (       (      )
    (       ((     (       (       )
                     (     ((     (                  ))
                                 )
                           ((       (                 )       )
                            (     (     ) (         )))
                           (   
                            (     (     )      ))))))
     (        ))))

                                                                      
(       (                       )
  (       (      )
    (        (    (                )             ))))


                                                           
(       (                     )
  (       ((     (       (                                       )
                   (   (                 )
                                   
                     (     ((         (               ))
                            (           (          )))
                       (   (                        )
                         (                         (               ))
                         (                                 (               ))))))))
   (     (               ) (  (               )) (               ))))

(       (                                                                                )
  (    ((                   (                 (       (   ) (  (                 )            ))           )))))

           (                                           )
(       (                                                                                       )
  (   (   (               )       
          (                )                    
          (                          )                                 
          (      (              )))                           
    (                                                )
    (     ((            (                             (           (                     ))))
           (                  (                 (       (      ) (    (                         )))
                                                                    ))
           (                 (                                         )))
     (   (                      )
       (                                                                         (               ))
       (    ((                (                 (       (    )
                                                  (     (       (     )
                                                          (    (        (                  ))
                                                               (       (                     )            )))
                                                                        ))
                                                          )))
         (                                                                                         ))))))


(       (                                                                                         )
  (              (                 (       (   ) (  (                 )                   ))           )
                                             
                        
                            ))


(                (                  (           )))

(                 (    ))

(                  (    ))

(                   (    ))

(              (                    (                                  ) (                       )                     ))

(              ) (       )

Name: >>89 2012-05-23 4:16

>>90
indeed.

Name: >>89 2012-05-23 4:20

>>90
whoa that actually looks neat when looking at the whole thing. It would make a good ascii ink blot if it was symmetrical.

Name: Anonymous 2012-05-23 4:26

>>91
My favourite part was
))))))))
What was yours?

Name: Anonymous 2012-05-23 4:34

>>93
I don't know...you know...I guess I sort of like em all...

Name: Anonymous 2012-05-24 0:10

pantsu

Name: bampu pantsu 2012-05-29 4:57

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List