Wrote the bulk of the information-theory-heavy code. I started by writing a function that takes a letter and a potential solution and returns a bitmask representing which spaces would be uncovered. For instance, get_bitmask('a', "banana") would give you 010101, since there are As at the 1st, 3rd, and 5th indices. Then I wrote a second function which, given a letter and a word list, returns the Shannon entropy, or the expected bits of information, of that letter. This involves counting the occurrences of every bitmask in the word list and taking a weighted sum of the number of bits gained. For instance, if my letter was e and my word list was [hello, lends, flees, stick], the bits of information you could expect to obtain from guessing e is p(01000) * log2(1 / p(01000)) + p(00110) * log2(1 / p(00110)) + p(00000) * log2( 1 / p(00000)), which equals 1.5. Obtaining the bitmask for a given letter and a given word of length l is O(l). Thus, calculating the entropy of a given letter for a certain word list of length n is O(n * l). Calculating the entropy for every one of r remaining letters is O(n * l * r). Since no English words are longer than a few dozen letters and there cannot be more than 26 remaining letters, determining the best letter to guess should be roughly linear with respect to the number of possible words. A few hundred thousand words through a linear-time algorithm should be nothing for Rust, but we will see whether my dubious asymptotic notation skills are supported by the final result. :) Unfortunately, there is not much to see in the screenshots I’ve been attaching; I use test-driven development and make sure my logic is reasonably sound before I even touch the UI, thus the rather boring images of passed unit tests.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.