My wife’s grandmother is a fearsome character. She’s in her nineties but still has all her wits about her. In fact, she’s got more than her fair share of wits. Whenever we visit her, she hits me with a barrage of questions and puzzles collected from the last several decades of TV quiz shows and newspaper games pages. My worth as a grandson-in-law is directly proportional to how many answers I get right.
One of her favourite modes of attack is the “30 Second Challenge” from the Daily Mail. It looks like this:
You start with the number on the left, then follow the instructions reading right until you get to the answer at the end. It’s one of Grandma’s favourites because it’s very hard to do in your head when she’s just reading it out!
I decided it would be a fun Sunday morning mental excursion to make a random 30 second challenge generator.
Making a random challenge generator involves thinking about what the space of possible challenges is, and how to pick fairly from them corresponding to different difficulty levels. The strategy I came up with is for each difficulty level to have a pool of possible operations, and to pick at random from those for each step. An operation can involve more than one step, and each operation has a function which looks at the current state of the puzzle to decide if it can be applied.
As far as I know, each operation must leave you with a whole number. That means that a “divide by $N$” instruction can only appear when your number is divisible by $N$. Since some divisors are much more common than others, but I wanted to have a good distribution of numbers to divide by, I made the divide by” operation pick a number $N$, and then add a step to add or subtract the right amount to get to a multiple of $N$, before adding the step to divide.
Some pairs of operations shouldn’t appear next to each other – you shouldn’t get an “add” followed by a “subtract”, or a “halve it” followed by a “double it”.
With a rough system of making valid challenges in place, I needed to make three difficulty levels. My rough rule of thumb was that dividing is really hard, cubing is hard because it leads to big numbers, and adding and subtracting are quite easy. I could probably split the additions or multiplications into easier or harder versions – there’s some evidence that the 6 and 8 times tables are hardest – and add some more complicated operations like “square root of this”. At the moment, I don’t feel like the difficulty levels are consistent enough: sometimes you’ll get a really easy “hard” challenge, and sometimes you’ll get a pretty tricky “easy” one.
Finally, I decided to look at accessibility. Grandma continues to be unsatisfied with me because her son-in-law, who’s partially sighted, always solves the challenges much quicker than I can. She reads the steps out and he does the calculations in his head. With that in mind, I made sure the challenge is usable when you can’t see it. Thanks to modern web standards, that was easy – I set
tabindex=1 on the step elements, so that you can navigate between them by pressing tab, and made sure all of the instructions make sense when read out by a screen reader: I had to add an
aria-label attribute to the fraction instruction with some alternate text to read out instead of the fancy formatting I use in the visual version. I tested it all with the ChromeVox extension, which works pretty well and is very easy to set up (arguably too easy – it went a bit mad reading every other tab I had open while I was testing).
In the end, this is how the finished game looks:
It was a fun excursion, and the game is pretty addictive. You can play it at christianp.github.io/30secondchallenge. Post your average times and record streaks in the comments!