Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Evaluating Logic Gates

Logic gates are functions which perform basic logic operations. In this problem, we will account for the following 6 logic gates: AND, OR, XOR, NAND, NOR, and XNOR. Each of these takes two boolean inputs \$ a \$ and \$ b \$, and outputs a boolean. Below are the truth tables which show the output of each gate given two inputs.

enter image description here

Task

Given two boolean inputs \$ a \$ and \$ b \$, return/output a list of the names of all gates which would return a Truthy value. The order doesn't matter, but the names must be in the exact format as given in the 2nd sentence of the above paragraph (not the ones in the diagram). You are also allowed to output them exclusively in lowercase, if desired.

Clarifications

  • You may also output a delimiter-separated string
  • I will allow leading/trailing spaces

Test Cases

Input

0 0
0 1
1 0
1 1

Output

[NOR, NAND, XNOR]
[OR, NAND, XOR]
[OR, NAND, XOR]
[OR, AND, XNOR]

This is , so the shortest code in bytes wins!

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ 37 bytes \$\endgroup\$ Commented Apr 28, 2020 at 2:25
  • 1
    \$\begingroup\$ @Jonah Nice. I knew that the N's are at nice positions, but somehow I missed that one. \$\endgroup\$ Commented Apr 28, 2020 at 2:40

AltStyle によって変換されたページ (->オリジナル) /