Skip to content
Tactiverge

School/△ Builder/Week 1

Trace every case with a rule table

A sorting machine reads three yes/no sensors. How many situations must its rules cover, and what happens in the one you forgot?

About 35 min · 3 goals · Checked by automated tests

1.Why should I care?

Machines meet every possible input eventually, including the ones nobody imagined. A rule table that lists every combination is a simple, powerful way to make sure an algorithm never reaches a case with no answer.

  • ◇ Count the input combinations a decision must handle.
  • ◇ Write a complete rule table so every combination has a defined action.
  • ◇ Use hand tracing of unusual inputs to find gaps in an algorithm.

2.Discover

Open the sorting machine at Level 2 and turn the client's brief into the full 8-row rule table: one bin for every combination of red, large and metal. Before you run it, trace two unusual parts by hand (a small red metal part, a large non-red plastic part) and predict their bins.

Can't use the interactive? Read a description instead

The sorting machine's Level 2 task is a table with 8 rows, one per combination of red (yes/no), large (yes/no) and metal (yes/no). For each row you choose a bin. The lesson can be done on paper: list the 8 combinations, apply the client's brief to each, and check every row has exactly one bin.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

A sorting machine's decision depends on 4 yes/no sensors and one selector switch with 2 positions. How many different input combinations must a complete test table contain?

rows

Practice 2

A rule table for 3 yes/no sensors has only 7 rows. What is the risk?

4.Apply it

Finish the sorting machine's Level 2 rule table and run it. Then add a fourth sensor (wet?) to the brief and work out how many rows the new table needs and which bin wet parts should go to.

Open BUILD 003: Create an Intelligent Sorting Machine →

5.Understand

Count the cases first

With k yes/no inputs there are 2^k combinations: 2, 4, 8, 16, … An input with m settings (a selector switch) multiplies the count by m. Counting tells you how many rows a complete rule table, or a complete set of tests, needs.

A rule table is an algorithm

Each row says: for this combination of inputs, do this. Because the rows cover every combination, there is no situation in which the machine has to guess. A rule table is also the easiest way to show a client exactly what the machine will do.

Trace the strange cases

Bugs hide in combinations nobody pictured: a part that is red and metal, a sensor that says large and small at once. Pick the oddest inputs and trace the algorithm by hand. If you cannot say what it does, the algorithm is incomplete.

Explain it another way

Like checking every door and window before leaving home: you go through them all, not just the ones you usually use.

Worked example 1

Brief: 'Metal parts go to bin A. Large non-metal parts go to bin B. Everything else goes to bin C.' Which bin gets a small red plastic part?

Not metal (so not A), not large (so not B), so bin C. Tracing each rule in order gives one clear answer, so this row is defined. Do this for all 8 rows to prove the brief is complete.

Common mix-ups

  • Testing the usual cases proves an algorithm works.
    ✓ Usual cases are where it was designed to work. Proof comes from covering every case, or at least the strange and boundary ones.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 3

Which test input is most likely to expose a gap in a sorting algorithm?

Practice 4

A machine has 4 yes/no sensors. How many rows does a complete rule table need?

rows

7.Predict

A machine reads three yes/no sensors: red?, large?, metal?. How many different combinations can it see?

Guess first. Being wrong here is how the surprise works.

8.Reflect

Concepts: Decomposition, algorithms and flowcharts · Testing and debugging · Logic gates and Boolean algebra