Input A: 1 Input B: 1 Output NAND(A, B): 0
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.
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.
|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.
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.