First, set the browser to Full Screen view, to give this worksheet and your code as much space as possible.
Then choose either one of the two options below:
Option 1: Start this worksheet from scratch
Option 2: Continue, or view, previous work
Following-on from 'Wordle 2: writing an automated solver', in this worksheet your challenge is to write an analyser that can evaluate:
Notice the following:
imports you will see all the code you have written
in the previous projects, plus some new code that you will be using and/or modifying in this worksheet.main routine - but you will be adding one.call grid in the first place.
call mark by evaluating the let instruction. (It could
still be a variable, but we have no need to re-assign it because it
defines mark anew each time around the while loop, anyway).
while loop need test only for whether the puzzle is solved, not
for the number of attempts, because we want to know how many attempts it takes even if that is 7 or more - though any such case
will eventually be counted as a failure to solve the puzzle.attemptNo should be initialised to 1 rather than 0,
and it should be incremented by 1 whenever the mark for an attempt
is not all-greens.
When your implementation of asserts) in test
Write a main routine that:
When you have this implemented, run the program to find out how many attempts it takes to identify the target words CHURN and then FIZZY.
Record your results here:
In order to identify the effectiveness of a Wordle solver we need to test it against all 2,315 valid target words, and from this determine the percentage of of the puzzles it was able to solve in 6 or fewer attempts, and, for those successes, the average number of attempts needed.
asserts to fail. Then look
at the stub implementation of the (Float, Float) which
means that it returns a '2-tuple'- a tuple containing two values - which both happen to be tuple(something, something).success, representing the number of puzzles solved within 6 attempts. For now, initialise it to an example value of 7.weightedSum, representing the sum of: (puzzles solved in one attempt x 1) + (puzzles solved in 2 attempts x 2) + and so on.
For now, initialise it to an example value of 8. Below this, define two more values - successPercent and average - but for each these use a let instruction (because we won't need to re-assign them):
For successPercent give it a calculated value, derived from success such that it will represent a percentage of the number of validTargets
rounded to one decimal place..
The average is the weightedSum divided by success rounded to two decimal places.
return instruction to return a tuple constructed from the values successPercent and average in that order.
assert in the test should pass - but this is an artifical result, down entirely to those
numbers used to initialise the variables! So once you have
established that your implementation so far is correct, change the initial values of success and weightedSum to zero
(causing the assert to fail again.)
Now we will calculate success the total number of puzzles that the algorithm solves within 6 attempts.
Add a loop that evaluates the number of attempts to solve each of the targetwords provided in validTargets,
and if that number is within the limit of six, increment the value of success by one.
Although none of the asserts in the new test will be passing yet, what do you notice about the two values that are being generated by the function in the test?
Now we will calculate the weightedSum of the number of successful attempts, from which the average is subsequently derived.
outcomes as an array of integers with seven members, initialised to zero.
(Strictly speaking we could manage with six members, since we are interested only in the outcomes of 1 to 6 attempts
- so the first element (number 0>) is wasted.
However, that's a small price to pay for simpler code - as you will see.for loop that goes through the index values from 1 to 6
(we can just ignore the unused element zero), then adds into weightedSum the value of that element times the index number.
Make sure you understand why this will produce the 'weighted sum' of the results.
When implemented, all the asserts in the test
Your task is now to re-write main to understake the analysis and present
the results.
main.main print the message 'Starting...' onto the display.constant allValidTargetWords is a single string containing 2,315 words separated by spaces. However, the
function "ARISE" as the chosen first attempt, and the list of inputStringWithLimits
you have just created from allValidTargetWords. Because this will pass back two values as a tuple, look up how to 'deconstruct' a tuple (show in Help)
into two values named successPercent and average. (You can do this in a let instruction.)Run the program
Record the results (% solved and the average number of attempts) here:
Finally, try changing ARISE to an alternative first attempt word. Maybe try a few likely candidates.
Record the result from the best first attempt word that you found, whether or not it was better than ARISE.
Hopefully you were impressed at the effectiveness of the algorithm that you wrote. It would likely beat many human players - over a reasonable run of puzzles!
You now have the option to
to explore the parts of the code that you haven't written such as the display logic.If you would like to share the working application with others, click file > save as standalone to
save it as a self-contained single web page that shows only
an enlarged version of the display tab runs the program automatically when it is opened, and which runs automatically when opened.
This standalone email file may be emailed to others. You might like to print a few more instructions within main and/or
add any of the refinements below.
If you have time, there are plenty of ways that you could extend this investigation into Wordle, including:
main to evaluate the effectiveness of using each of the valid target words
as the first attempt, and keeping a running track of the best so far. Warning: this could take several hours to complete! Even more
ambitious (and taking more than seven times longer) would be to try it for each of the 15,000+ validAttempt words as the first attempt.