Skip to main content
1 of 2
Bubbler
  • 78.4k
  • 5
  • 149
  • 469

J, 39 bytes

[:;('NAND ';'NOR X';'NOR')}.~&.>*,+.,~:

Try it online!

A solution that pretty much works like Surculose Sputum's Python 3 answer.

How it works

[:;('NAND ';'NOR X';'NOR')}.~&.>*,+.,~:  NB. Input: two bits as left/right args
                                *,+.,~:  NB. evaluate AND, OR, XOR
   ('NAND ';'NOR X';'NOR')               NB. corresponding three segments
                             &.>  NB. pair up both sides unboxed and
                          }.~     NB.   drop the first char from left if right is 1
[:;  NB. Remove boxing and concatenate into a single vector
Bubbler
  • 78.4k
  • 5
  • 149
  • 469