Example
Input A: 1
Input B: 1
Output NAND(A, B): 0
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.
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.
Difficulty | Timesink | ||
---|---|---|---|
Function | NAND(A, B) |
You must be logged in to view your submissions.
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. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.