Skip to main content
1 of 2
Arnauld
  • 197.6k
  • 20
  • 179
  • 650

#JavaScript (ES6), 55 bytes

a=>b=>'1OR 3AND X5OR'.replace(/\d/g,n=>n>>a+b&1?'N':'')

Try it online!

###How?

For each gate type, we use the sum of \$a\$ and \$b\$ to right-shift a bit mask. We test the least significant bit of the result to find out if we must return the complementary form of the gate.

   a  | 1 | 0 | 1 | 0 |
   b  | 1 | 1 | 0 | 0 |
------+---+-------+---+---------
  a+b | 2 |   1   | 0 | decimal
------+---+-------+---+---------
  NOR | 0 |   0   | 1 |    1
 NAND | 0 |   1   | 1 |    3
 XNOR | 1 |   0   | 1 |    5

#JavaScript (ES6), 55 bytes

Using a template literal is just as long.

a=>b=>['N'[a|b]]+`OR ${['N'[a&b]]}AND X${['N'[a^b]]}OR`

Try it online!

Arnauld
  • 197.6k
  • 20
  • 179
  • 650