You are stranded on an Island when you bump in to 3 people. Of the three people (Alice, Bill, Charlie):

- One is a knight
- One is a knave
- One is a spy

On this island:

- Knights always tell the truth
- Knaves always lie
- Spies can do either

Alice says: “*Charlie is a knave.*“

Bill says: “*Alice is a knight*.”

Charlie says: “*I am the spy.*“

**Who is the knight, who the knave, and who the spy?**

All data stored in computer systems is stored in binary format, which means that any calculations that are made must be done using only **True** and **False** values, this is known as **Boolean** logic.

Take for the instance the set up below:

When we run the code below, scratch will either say “True” or “False”, depending on whether you press the let arrow key.

**Input** – Press the let arrow key

**process** – No processing

**Output** – True

When we are working out what possibilities exist for a particular Boolean logic structure, we can use a truth table to represent that data.

Using the previous example we can produce a simple truth table for the results.

Input |
Output |

1 |
1 |

0 |
0 |

A Boolean AND gate works by the following rules:

- If both inputs are true, then the output will be True.
- Otherwise the output will be false

#### Challenge 1 – Complete the AND gate truth table.

**Can you complete the truth table below?**

Input 1 |
Input 2 |
Output |

0 |
0 |
0 |

0 |
1 |
0 |

A Boolean OR gate works by the following logic:

- If either input is True, the output is True.
- If both inputs are True, the output is True.
- Otherwise the output is false.

#### Challenge 2

**Can you work out the truth table for a Boolean OR gate?**

Input 1 |
Input 2 |
Output |

0 | 0 | 0 |

0 | 1 | 1 |

1 | ||

1 |

A Boolean NOT gate simply reverses whatever input is given.

- If the input is True, the output is False
- If the input is False, the output is True

#### Challenge 3

Can you write truth table for a not gate?

Input |
Output |

0 |
1 |

1 |
0 |

Some logic requires combinations of different Boolean Logic Gate.

These are similar to OR gates but:

- If either input is True (but not both) the output is True
- Otherwise the output is false

#### Challenge 4

Can you use scratch blocks to make an XOR gate.

p.s. You can use the internet to help you if you like.

A NAND gate works with the following logic:

- If both inputs are True the output is False.
- Otherwise the output is true for all other cases