Skip to main content
added 368 characters in body
Source Link
Bubbler
  • 78.4k
  • 5
  • 149
  • 469

J, 3939 37 bytes

[:;('NAND_5<\'NAND ';'NORNOR X';'NOR'XNOR')}.~&.>*,+.,~:

Try it online!Try it online!

-2 bytes thanks to @Jonah.

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

How it works

NB. The three segments in the new version
_5<\'NAND NOR XNOR'
    'NAND NOR XNOR'  NB. a length-13 string
_5<\                 NB. enclose non-overlapping length-5 chunks
      (which works because the three N's to filter appear at indexes 0, 5, 10)

NB. Previous version
[:;('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

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

J, 39 37 bytes

[:;(_5<\'NAND NOR XNOR')}.~&.>*,+.,~:

Try it online!

-2 bytes thanks to @Jonah.

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

How it works

NB. The three segments in the new version
_5<\'NAND NOR XNOR'
    'NAND NOR XNOR'  NB. a length-13 string
_5<\                 NB. enclose non-overlapping length-5 chunks
      (which works because the three N's to filter appear at indexes 0, 5, 10)

NB. Previous version
[:;('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
Source Link
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