←
Build the decisionSaved automatically
Tutorial · Grade 229. Prime or Not

Send each prime number to the Prime Block. Send every other number to the Non-Prime Block.

Scenario

A prime number is bigger than 1, and only 1 and the number itself divide into it evenly. Examples are 2, 3, 5, 7 and 11.

Problem statement

Welcome back to the number desk. This time you are sorting prime numbers.

A prime number is bigger than 1. Only two numbers divide into it evenly: 1 and the number itself.

7 is prime. Only 1 and 7 divide into it evenly.

9 is not prime. 3 also divides into it, because 3 × 3 = 9.

1 is not prime. 2 is prime, and it is the only even prime number.

The desk checks each item for you, so you do not need to do any maths. You can see the facts it gives you in the Conditions tab.

Right now there are no rules. The cards wait and nothing moves.

Your task: build a rule that sends every prime number to the Prime Block. Then build a rule that sends every other number to the Non-Prime Block.

Rules are checked from the top, and the first rule that is true wins. So the order of your rules matters.

Be careful: odd is not the same as prime. 9, 15 and 21 are odd, but they are not prime. 2 is even, but it is prime.

What this teaches

How to pick the fact that really answers the question, instead of one that only looks similar.

Scroll down to build and test your solution.

Active controller

Apply & Run executes only the selected controller.

How a rule works

A rule has two parts:

WHEN <something is true> → DO <this action>

  • WHEN is a question about what is happening right now. For example: "Is it raining?" or "Is there a wall ahead?"
  • DO is what happens when the answer is yes.
  • The simulation runs one step at a time.
  • On each step, the rules are checked from top to bottom.
  • The first rule that is true wins. The rules below it are skipped for that step.
  • To change which rule wins, move it up or down the list.
  • If no rule is true, nothing happens on that step.
  • Some actions have more than one step, like "turn right, then move". You build these in the Functions tab.
  • Once a multi-step action starts, it finishes all its steps before the rules are checked again. It only stops early if the next step is not safe.
See an example

Two rules for deciding about an umbrella:

1  WHEN isRaining  → take an umbrella
2  WHEN always     → leave the umbrella at home
  • It is raining. Rule 1 is true, so you take an umbrella. Rule 2 is skipped.
  • It is sunny. Rule 1 is false, so rule 2 is checked next. Rule 2 is always true, so you leave the umbrella at home.
  • Order matters. If rule 2 were on top, it would be true every day, and you would never take an umbrella.

Rule folders

Categorise cards without changing their global execution order.

No rules yet. Nothing will happen until you add at least one rule.