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

★【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-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

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