# Exercise 27: Memorizing Logic

Today is the day you start learning about logic. Up to this point you have done everything you possibly can reading and writing files, to the Terminal, and have learned quite a lot of the math capabilities of Ruby.

From now on, you will be learning *logic*. You won't learn complex theories that academics love to study but just the simple basic logic that makes real programs work and that real programmers need every day.

Learning logic has to come after you do some memorization. I want you to do this exercise for an entire week. Do not falter. Even if you are bored out of your mind, keep doing it. This exercise has a set of logic tables you must memorize to make it easier for you to do the later exercises.

I'm warning you this won't be fun at first. It will be downright boring and tedious but this teaches you a very important skill you will need as a programmer. You *will* need to be able to memorize important concepts in your life. Most of these concepts will be exciting once you get them. You will struggle with them, like wrestling a squid, then one day you will understand it. All that work memorizing the basics pays off big later.

Here's a tip on how to memorize something without going insane: Do a tiny bit at a time throughout the day and mark down what you need to work on most. Do not try to sit down for two hours straight and memorize these tables. This won't work. Your brain will retain whatever you studied in the first 15 or 30 minutes anyway. Instead, create a bunch of index cards with each column on the left (true or false) on the front, and the column on the right on the back. You should then take them out, see the "true or false" and immediately say "true!" Keep practicing until you can do this.

Once you can do that, start writing out your own truth tables each night into a notebook. Do not just copy them. Try to do them from memory. When you get stuck glance quickly at the ones I have here to refresh your memory. Doing this will train your brain to remember the whole table.

Do not spend more than one week on this, because you will be applying it as you go.

# The Truth Terms

In Ruby we have the following terms (characters and phrases) for determining if something is "true" or "false." Logic on a computer is all about seeing if some combination of these characters and some variables is true at that point in the program.

`&&`(and)`||`(or)`!`(not)`!=`(not equal)`==`(equal)`>=`(greater-than-equal)`<=`(less-than-equal)`true``false`

You actually have run into these characters before, but maybe not the terms. The terms (and, or, not) actually work the way you expect them to, just like in English.

# The Truth Tables

We will now use these characters to make the truth tables you need to memorize.

NOT | true? |
---|---|

!false | true |

!true | false |

OR (||) | true? |
---|---|

true || false | true |

true || true | true |

false || true | true |

false || false | false |

AND (&&) | true? |
---|---|

true && false | false |

true && true | true |

false && true | false |

false && false | false |

NOT OR | true? |
---|---|

not (true || false) | false |

not (true || true) | false |

not (false || true) | false |

not (false || false) | true |

NOT AND | true? |
---|---|

!(true && false) | true |

!(true && true) | false |

!(false && true) | true |

!(false && false) | true |

!= | true? |
---|---|

1 != 0 | true |

1 != 1 | false |

0 != 1 | true |

0 != 0 | false |

== | true? |
---|---|

1 == 0 | false |

1 == 1 | true |

0 == 1 | false |

0 == 0 | true |

Now use these tables to write up your own cards and spend the week memorizing them. Remember though, there is no failing in this book, just trying as hard as you can each day, and then a *little* bit more.

# Common Student Questions

- Can't I just learn the concepts behind boolean algebra and not memorize this?
- Sure, you can do that, but then you'll have to constantly go through the rules for boolean algebra while you code. If you memorize these first, it not only builds your memorization skills, but it also makes these operations natural. After that, the concept of boolean algebra is easy. But do whatever works for you.