01/28/22

Exploring Wordle with Julia: Part I

Wordle is a fun and easy game that has shot to fame recently. It is completely minimalistic, no-fills and highly addictive. We will explore here how to write as simple solver for Wordle with Julia and then adding layers of complexity and sophistication as we go along.

In Wordle we are successively guessing five-letter words. After each guess the game tells us which of our letters occur in the secret word and whether they are in the correct position. As explained in their website.

So after each guess we narrow the set of possible words to choose from till we arrive at the secret word, and we only have six tries.

Our Dictionary

Wordle only deals with a valid five-letter English words. So we need to start grabbing such words. A good place to start is the Standford GraphBase data set.

Constraints

The next step is the try narrow down the set of feasible words as we are getting clues. Towards that end, we construct a `Dict` to map letters that are in the word at the correct spot to their location, another `Dict` to maps letter in the word that are in the wrong spot, and finally a `Set` of letters that are not in the word:

Now we can encode the the response we get the game as `String` of numbers, where 0 means that the character is not in the word, 1 means the that character is the word but not in the right spot, and 2 means that the character is in the word at the correct spot. For example

```Secret Word:    perky
Candidate Word: ebony
Response:       10002```

We can update our set of constraint for any response by the following function:

Shrinking the feasible set of words

The constraints will reduce the feasible set of possible words. This can be done by applying filters that make use of constraints as in the following function:

Putting it all together

So all what we have to do now is to apply the following step

1. Guess a candidate first word
2. Get response from the Game
3. Use that response to update the set of constraints
4. Use the constraints to reduce the set of possible words
5. Guess the new candidate word
6. Repeat step 2 until a word is found or the game is over

In the steps 1 and 5 above, the simplest approach is just to pick a word at random. Below is Julia repl session showing how we go about applying the above. The secret word here is “super”

We see that we arrived at the correct word after guessing

• excel
• fumer
• purer
• super

That is a 5/6 score. Not too bad! But we could do better. How? We explore that in the next part.

See also below an interactive session where the secret word is “wrung”

01/28/22

Expanding WordPress Julia’s GeSHi Syntax Highlighting

In your WordPress installation you want to modify the `wp-content/plugins/wp-geshi-highlight/geshi/geshi/julia.php `file.

``````/*
** builtins
*/
2 => array(
'Array', 'String', 'Bool', 'Number', 'Int', 'Integer', 'Real', 'Complex',
'FloatingPoint', 'Float64', 'Float32', 'Int8', 'Int16', 'Int32', 'Int64',
'Rational', 'AbstractArray', 'Unsigned', 'Signed', 'Uint', 'Uint8', 'Uint16',
'Uint32', 'Uint64', 'Vector', 'AbstractVector', 'Matrix', 'AbstractMatrix',
'Type', 'IO',....
``````

You are trying to expand the list of those `builtins`. In Julia, you extract that list by running

`julia> [names(Core);names(Base)] .|> String |> x->filter(z->occursin(r"^[A-Za-z]+[A-Za-z0-9]+",z),x) |> x->join(["'\$y'" for y in x],", ") |> x-> replace(x,r"(.{30,75},)\s"=>SubstitutionString(" "^12*"\\1\\n"))|> clipboard`

You take the output in the clipboard and replace the contents of the aforementioned array.