AND, OR and NOT as Puzzles

AND, OR and NOT are the most basic operations a computer uses to make decisions. They are called logic operations. As soon as children start programming, they meet them in the form âif A and Bâ or âif A or Bâ.
The words sound technical, but what they mean is almost the same as everyday language. In this post I explain the three operations with familiar examples and turn them into puzzles you can play at home.
True and false
Logic operations do not work with numbers. They work with whether something is right or not. Something that is right is called true, and something that is not is called false.
âIt is raining todayâ is true on a rainy day and false on a sunny one. â7 is greater than 10â is always false. Logic operations take answers like these, true or false, and combine them or turn them over.
NOT: turn it over
NOT turns true into false and false into true.
If âit is rainingâ is true, then âit is not rainingâ is false. If âit is rainingâ is false, then âit is not rainingâ is true. The word ânotâ in English is exactly this operation.
Two NOTs in a row bring you back to where you started. âIt is not the case that it is not rainingâ means the same as âit is rainingâ. It is a little like multiplying by â1 twice, which gives back the original number.
AND: both at once
AND is true only when both conditions are true.
Take this rule: if it is raining and it is cold, wear a coat. You wear the coat only on days that are both rainy and cold. On a warm rainy day, or a cold sunny one, you do not.
Here is that rule for every combination. A table like this is called a truth table.
| It is raining | It is cold | Wear a coat (AND) |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
Only one of the four rows is true. You could say AND makes a condition strict.
OR: at least one
OR is true when at least one of the two conditions is true.
Take this rule: if it is raining or it is very windy, walk instead of cycling.
| It is raining | It is windy | Walk (OR) |
|---|---|---|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |
This time three of the four rows are true. OR makes a condition loose.
There is one place where children often trip up: the first row, a day that is both rainy and windy. In logic, OR is true when both are true. But in everyday speech, âorâ often means picking only one, as in âcoffee or tea?â. I think it helps to say clearly, at least once, that logical OR means âone or the other, or bothâ. The operation that is true when exactly one is true has its own name, XOR, exclusive or.
Thinking with a switch circuit
A circuit with a battery, a bulb and switches makes the difference between AND and OR visible.
Put two switches one after the other on a single path (in series), and the bulb lights only when both are on. That is AND. Put the two switches on separate paths (in parallel), and turning on either one lights the bulb. That is OR. If âswitch onâ means true and âbulb litâ means true, you get exactly the truth tables above.
I think this comparison is worth using, because inside a computer, logic operations really are done by combinations of tiny electrical switches. It is less a metaphor than a description.
Word puzzles at home
You do not need any equipment. Words are enough.
Point around the room and ask, âWhich things are red and round?â That is AND. An apple fits, but a red book or a white ball does not. Then ask, âWhich things are red or round?â That is OR, and the apple, the red book and the white ball all fit.
It is also fun to let the child set the questions. Ask them to âuse NOT to make a question that only one thing in this room fitsâ, and you get questions like âsomething that is not square and is on the tableâ. Combining conditions until only one answer is left is the same kind of thinking as writing conditions in a program.
Once that is easy, you can try something harder. Do âthings that are not (red and round)â and âthings that are not red, or not roundâ point to the same objects? They do. This is a rule called De Morganâs law, which children usually meet later in school maths. Even without the name, I think they can feel it by checking with things in the room.
The link to programming
Scratch, which many schools use, has blocks called âandâ, âorâ and ânotâ. They are exactly AND, OR and NOT. Put them inside an âifâ block and you can build conditions such as: if the space key is pressed and the sprite is touching the ground, jump.
When a condition does not behave as expected, I suggest writing a truth table. Write the four rows and check what you want to happen in each case. You will notice if AND and OR have been swapped, or if NOT is in the wrong place. What programming education in school aims for is in What Do Children Learn in Elementary School Programming?, and the kind of thinking puzzles build is in What Is Computational Thinking, and What Can Puzzles Teach?.
The Logic Circuit in Math Gates
Math Gates is a circuit puzzle game I make. You place gates that change a number and mirrors that turn its path 90 degrees on the empty cells of a board, then press Run. A bit carrying a number travels in a straight line. The port at the end accepts only values that meet its condition.
The last of the seven worlds, Logic Circuit, is what this post is about. When the bit passes a comparison gate such as v>n or v<n, its number turns into true or false. It then goes through NOT, AND and OR logic gates, and you succeed if it reaches the port with a value that meets the condition. Some ports take âtrueâ as their condition. As soon as you place a piece, the bitâs path and how its value changes are drawn on the board as a dotted line, so you can follow where true and false flip before you press Run. When you clear a puzzle, you get a discovery card that gives what you just did a name and a formula.
There are 140 puzzles across seven worlds, aimed at ages 8 and up. It is free to play with ads between puzzles, and a one-time purchase removes the ads. How to play is in Getting Started with Math Gates.
I think AND, OR and NOT are not special words for computers. They are the âandâ, âorâ and ânotâ we use every day, given a precise shape.
