The Numbers game – part 4

Finally, following on from version 3 of this program, I have now finished the bones of Version 4. Very similar to Version 3, but instead of using a PHP script running on the server, this now uses Javascript running within the single page. This removes any restrictions regarding server speed, and puts all the processing on the device running the page on the browser. Using Firefox on my desktop machine (Intel(R) Pentium(R) CPU G4560T @ 2.90GHz 2.90 GHz with 16GB ram) it process all possible combinations of numbers and signs (29,967,840) within about 20 seconds. On my phone (Ulefone Power Armor 14), it attempts about 17,000,00 of 29,967,840 combinations in 30 seconds. On my son’s newer, faster phone it processes all 29,967,840 combinations in 10.32 seconds! That’s 5 times faster than my phone. 🙁
Talking of phones, there is special mobile version to use while watching Countdown.
The user interface is a little different. There are now 3 options for processing.

1. To show just 10 lines of matches
2. to show 30 seconds of results, up to 100 matches are shown if found.
3. to show all matches, but only 100 are shown on the screen.

When the solve button is clicked, a small line of text appears in the results saying “Calculating…”.

JavaScript seems to have an issue updating the Dom before going into the very long solving routine, so there was no indication on the screen that the Solve button had been pressed. I spent a couple of days looking for answers to this one, and came upon this one by accident while researching a different issue.

solveobj.disabled = true;
clearobj.disabled = true;
resultsobj.innerHTML = ("Calculating... ");

sleep(100).then(() => {resultsobj.innerHTML = (solveEnglish (selnumbers, targettotal, solvetype))});

clearobj.disabled = false;
solveobj.disabled = false;

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));

I do love the existence of a programming instruction "Promise", when I wrote my first program 51 years ago this would have seemed very strange, nowadays I just accept the weird people who contribute to developing programming languages! A big thank you to James Hibbard for this page and his description of what a promise is in Javascript. This is the simplest and easiest implementation I have come across. Using this I was able to replace the results space with a meaningful 'Calculating...' which shows up until the real results appear.

I think this project is probably almost finished, time to look for something else to keep me busy.