项目作者: at1as

项目描述 :
Simple hangman solver written in Crystal
高级语言: Crystal
项目地址: git://github.com/at1as/Hangman.git
创建时间: 2017-10-07T19:37:33Z
项目社区:https://github.com/at1as/Hangman

开源协议:

下载


Hangman

Simple script to solve hangman.

Does the following:

  • Selects a word a random from the dictionary
  • Given the length of the word, finds the most common letter occurances across all words of that length
  • Simple algorithm
    • Guesses most common letters until solution is found
  • Improved algorithm
    • Filters for most common letters at every iteration for dictionary words that match pattern of the guessed letters
    • Continues until solution is found

Note: Syntax is nearly Ruby compatable, however tuple types need to be changed to Hash and type decleration needs to be removed from the array.

Usage

  1. $ crystal hangman.cr

Output

Simple Algorithm

  1. $ crystal hangman.cr --error-trace
  2. Selecting a word from the dictionary at random...
  3. The word is --------- (9 of 9 digits remaining)
  4. Solving using simple algorithm...
  5. Trying with e...
  6. The word is ------e-- (8 of 9 digits remaining)
  7. Trying with i...
  8. The word is ------e-- (8 of 9 digits remaining)
  9. Trying with a...
  10. The word is --a---e-- (7 of 9 digits remaining)
  11. ...
  12. Trying with y...
  13. The word is crac-less (1 of 9 digits remaining)
  14. Trying with g...
  15. The word is crac-less (1 of 9 digits remaining)
  16. Trying with b...
  17. The word is crac-less (1 of 9 digits remaining)
  18. Trying with f...
  19. The word is crac-less (1 of 9 digits remaining)
  20. Trying with v...
  21. The word is crac-less (1 of 9 digits remaining)
  22. Trying with k...
  23. The word is crackless (0 of 9 digits remaining)
  24. Solved after 22 iterations with simple algorithm

Improved Algorithm

  1. Solving using improved algorithm...
  2. Trying with e...
  3. The word is ------e-- (8 of 9 digits remaining)
  4. Trying with s...
  5. The word is ------ess (6 of 9 digits remaining)
  6. Trying with n...
  7. The word is ------ess (6 of 9 digits remaining)
  8. Trying with l...
  9. The word is -----less (5 of 9 digits remaining)
  10. Trying with r...
  11. The word is -r---less (4 of 9 digits remaining)
  12. Trying with t...
  13. The word is -r---less (4 of 9 digits remaining)
  14. Trying with a...
  15. The word is -ra--less (3 of 9 digits remaining)
  16. Trying with c...
  17. The word is crac-less (1 of 9 digits remaining)
  18. Trying with k...
  19. The word is crackless (0 of 9 digits remaining)
  20. Solved after 10 iterations with improved algorithm

Notes

  • Build on Crystal 0.23.1 (2017-09-08) LLVM 4.0.1
  • Requires list of words to be under /usr/local/share/dict as is default on macOS