https://github.com/at1as/hangman
Simple hangman solver written in Crystal
https://github.com/at1as/hangman
algorithm crystal dictionary game hangman terminal
Last synced: 19 days ago
JSON representation
Simple hangman solver written in Crystal
- Host: GitHub
- URL: https://github.com/at1as/hangman
- Owner: at1as
- Created: 2017-10-07T19:37:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-07T20:11:17.000Z (about 8 years ago)
- Last Synced: 2025-05-20T06:37:23.058Z (5 months ago)
- Topics: algorithm, crystal, dictionary, game, hangman, terminal
- Language: Crystal
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 foundNote: 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
```
$ crystal hangman.cr
```## Output
### Simple Algorithm
```
$ crystal hangman.cr --error-traceSelecting a word from the dictionary at random...
The word is --------- (9 of 9 digits remaining)
Solving using simple algorithm...Trying with e...
The word is ------e-- (8 of 9 digits remaining)Trying with i...
The word is ------e-- (8 of 9 digits remaining)Trying with a...
The word is --a---e-- (7 of 9 digits remaining)...
Trying with y...
The word is crac-less (1 of 9 digits remaining)Trying with g...
The word is crac-less (1 of 9 digits remaining)Trying with b...
The word is crac-less (1 of 9 digits remaining)Trying with f...
The word is crac-less (1 of 9 digits remaining)Trying with v...
The word is crac-less (1 of 9 digits remaining)Trying with k...
The word is crackless (0 of 9 digits remaining)Solved after 22 iterations with simple algorithm
```### Improved Algorithm
```
Solving using improved algorithm...Trying with e...
The word is ------e-- (8 of 9 digits remaining)Trying with s...
The word is ------ess (6 of 9 digits remaining)Trying with n...
The word is ------ess (6 of 9 digits remaining)Trying with l...
The word is -----less (5 of 9 digits remaining)Trying with r...
The word is -r---less (4 of 9 digits remaining)Trying with t...
The word is -r---less (4 of 9 digits remaining)Trying with a...
The word is -ra--less (3 of 9 digits remaining)Trying with c...
The word is crac-less (1 of 9 digits remaining)Trying with k...
The word is crackless (0 of 9 digits remaining)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