Welcome to Project Lovelace! We're still super new so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or any comments at all please let us know on Discourse!

NAND gate

You will learn about: logic gates and if statements.

You have hundreds of millions of logic gates in your phone and laptop. They're tiny circuits that work with 0's and 1's and perform basic boolean operations, usually with 2 inputs.


Truth tables for the NOT, AND, and NAND logic gates. (Source: Wikipedia: NAND logic)

A simple logic gate would be the NOT gate, which inverts the input so a 0 becomes a 1 and vice versa. An AND gate produces 1 only if both of its inputs are 1, otherwise it produces 0. The NAND gate is a an AND gate followed by a NOT gate, so it's performing a (NOT AND) operation. Try to write a function NAND(A, B) that returns the output of a NAND gate.


Input: Two integers A and B that have the value 0 or 1.

Output: The output of a NAND gate with inputs A and B.


Example

Input A: 1 Input B: 1 Output NAND(A, B): 0


 Difficulty  Timesink
 Maximum runtime 60 s  Max. memory usage 250 MiB
 Function signature NAND(A, B)

Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.




You must be logged in to view your submissions.

Notes

  • All logic gates are made using transistors so transistors are the building blocks of all phones and computers.
  • The NAND gate (and NOR gate) is special in that it's a universal gate so you can build any other gate using a NAND gate. You could even build a CPU completely out of NAND gates, although it would probably be bigger and slower than if you just used the actual gates you needed.
  • NAND to Tetris teaches you how to build a computer that plays tetris from the ground up starting with NAND gates!

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Feel free to post your solutions but if you do please organize and document your code well so others can learn from it.