Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite solving #4

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Experiments in Wordle solving via SQLite pre-computations.
# Results in ~500MB database of this name via "make wordle_solve.db"
wordle_solve.db


# Poetry.lock is an exact version pinning tool (down to SHA256 of libs)
# If writing a (reusable) library, exact versions don't matter that
# much so it may make sense to gitignore that file, uncomment the following line:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ code changes being just patching bugs.

<!-- This section kept empty on purpose to help write un-released changelogs. See https://keepachangelog.com/en/1.0.0/#effort for more reasoning. -->

### Added
- New python file `sqlite_solve.py` for solving Wordle via brute-force
pre-computation of scores given known guesses/answers, saved in database file.


## [1.1.0] - 2022-06-13
### Fixed
- Bug in guess scoring when a letter occurs twice in guess, but only once (second time) in answer, see [bug #1](https://github.com/OverkillGuy/literate-wordle/issues/1). Thanks to [@gpiancastelli](https://github.com/gpiancastelli) for reporting!
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ docs-serve:
build:
poetry build

# Not a phony target = real file!
wordle_solve.db:
poetry run python src/literate_wordle/sqlite_solve.py



# Proper Makefile target:
# The file wordle.html is actually generated from wordle.org with that command
# Note: Any modifications (last edit time) of wordle.org will cause rebuild wordle.html
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ Use this package as you would any python module:
>> print(f"Hello! The secret wordle answer is '{answer}'.")
Hello! The secret wordle answer is 'blank'.

### Solve Wordle!

An exploration of solving Wordle via statitical brute-force is done in the
`src/literate_wordle/sqlite_solve.py` module. Pre-compute the scores for all answers for all valid
guesses by running:

make wordle_solve.db

This should create ~500MB sqlite3 database for you to explore. Table schema is
in `src/literate_wordle/db/tables.sql`.

Some exploratory SQL queries can be found in
`src/literate_wordle/db/find_solution.sql`.

Try the database once created via:

sqlite3 wordle_solve.db
# Try asking this to list available tables:
.tables


## Development

### Python setup
Expand Down
57 changes: 57 additions & 0 deletions diagram.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@startuml

/' Skin from SQL Plantuml blog[1]
'[1]: https://raphael-leger.medium.com/automatically-generating-up-to-date-database-diagrams-with-typeorm-d1279a20545e
'/

left to right direction
skinparam roundcorner 10
/'
' skinparam linetype ortho
'/
skinparam shadowing false
skinparam handwritten false

skinparam class {
BackgroundColor white
ArrowColor #2688d4
BorderColor #2688d4
}

!define table(x) class x << (T, white) SQL Table >>

table( score_index ) {
scoreidx: int
score: text
}
table( word_index ) {
wordidx: int
word: text
}
note bottom of word_index
Superset of all valid wordle words = accepted guesses
end note

note bottom of answers_index
Wordle answers = subset of accepted guesses, referencing word_index
end note

table( answers_index ) {
wordidx: int
}

answers_index::wordidx --> word_index::wordidx : FK

note bottom of scores
Computed score of a guess (word) against an answer (word) all via index
end note
table( scores ) {
guessidx: int
answeridx: int
scoreidx: int
}
scores::guessidx --> word_index::wordidx : FK
scores::answeridx --> word_index::wordidx : FK
scores::scoreidx --> score_index::scoreidx : FK

@enduml
Binary file added diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading