Skip to content

What is a rule?

Rules are the core of how a mental-math exercise is designed. Each rule is a short expression that decides whether a player's chosen value is allowed at a given step. When a player picks a number, every rule in the ruleset is checked against that candidate. If any rule rejects it, the move is blocked.

This guide teaches you how to write rules from scratch — no prior experience required. You do not need to be a programmer: a rule is closer to a sentence than to a program.

Here is a complete, real rule:

current_value > 0 AND formula = 8 AND digitBefore IN (0, 1)

Read left to right, it says: the operation is an addition, it is an "8", and the digit it affects is currently 0 or 1. By the end of the guide, every part of that line will be familiar.

The three outcomes

A rule is a single expression that evaluates to one of three outcomes:

OutcomeMeaning
PassedThe condition is satisfied. This rule does not block the move.
FailedThe condition is not satisfied. The move is rejected.
SkippedThe rule has an IF guard that was false. The rule does not apply to this step and does not block the move.

The distinction between Failed and Skipped is what makes rules composable. A rule that does not apply to the current step steps aside instead of objecting — so you can write narrow, single-purpose rules without them fighting each other.

How a ruleset combines rules

A ruleset is a collection of rules. All rules run against every candidate value. A value is only allowed if every rule passes or skips. One failing rule is enough to reject it.

Rules restrict; they do not propose

A ruleset never suggests a value. It only narrows the set of values that are permitted. A recipe is what turns that permitted set into an actual generated exercise, by giving each rule a job — target, review, filler, forbidden, or constraint.

Where to go next

  • Your first rule — write a working expression in two minutes.
  • Variables — the values a rule can talk about.
  • Operators — comparisons, arithmetic, AND/OR/NOT, IF…THEN, IN.
  • Decimal placesplace, formula, and digitBefore, which almost every real rule is built from.

Reference and cookbook for mental-math rule and recipe authoring.