g | x | w | all
Bytes Lang Time Link
216BrainFlak250117T224454ZMegaTom
021Japt250114T123336ZShaggy
02305AB1E250113T090412ZKevin Cr
040Bash250105T154545ZGammaFun
059AWK250103T182127Zwobtax
048Google Sheets241227T033519Zdoubleun
048Google Sheets241228T014451Znoodle p
025Uiua241225T160805Znoodle p
037Zsh241226T195451ZGammaFun
051Common Lisp241226T164654ZAlephSqu
049Perl 5 pl241226T060121ZXcali
4845C241225T173721Zm90
149R241225T204937ZEonema
018Charcoal241225T194719ZNeil
132brainfuck241225T185339ZLevel Ri
070Vim241225T190456ZFmbalbue
022Jelly241225T185856ZUnrelate
045JavaScript ES6241225T183731ZArnauld
033Jelly241225T174007ZFmbalbue
043JavaScript Node.js241225T003739Zl4m2
056APL+WIN241225T083443ZGraham
039Retina 0.8.2241225T005726ZNeil
044Python241225T000548ZUnrelate

Brain-Flak, 216 bytes

((({})<({}[{}]<><(((((((()()()()){}){}()){}){})(()()()()()){})[((()()()){}){}()])>){(<{}(([{}]{}{}())[()()()])>)}{}><>)){{}<>((((()()()){}){}){({}[()])}{})(<>)}{}({}<{}>{}[()]){<>(((((()()()()()){}()){}){}){})(<>)}<>

Try it online!

Japt, 22 21 bytes

Takes input as 4 individual bits, outputs in lowercase.

çÍixsUaX¹+`d `¸gUaV

Try it

AND, NAND, OR, NOR, XOR, XNOR

Explanation

çÍixsUaX¹+`...`¸gUaV     :Implicit input of bits U, V, W (unused) & X
ç                        :Repeat U times
 Í                       :  "n"
  i                      :Prepend
   x                     :  "x"
    s                    :  slice from 0-based index
     UaX                 :    Absolute difference of U & X
        ¹                :End prepend
         +               :Append
          `...`          :  Compressed string "and or"
               ¸         :  Split on spaces
                g        :  Get element at 0-based index
                 UaV     :    Absolute difference of U & V

05AB1E, 23 bytes

ćÅ¿'x×Iн'nׄ€—€ƒ#I2£ËèJ

Input as a string.

Try it online or verify all test cases.

Explanation:

ć           # Extract head of the (implicit) input-string; push first item and
            # remainder-string separately
 Å¿         # Check if the remainder-string ends with this first bit
   'x×     '# Repeat "x" that check (0 or 1) amount of times
I           # Push the input-string again
 н          # Pop and push its first bit
  'n×      '# Repeat "n" that bit amount of times
„€—€ƒ       # Push dictionary string "or and"
     #      # Split it on spaces: ["or","and"]
      I     # Push the input-string yet again
       2£   # Pop and keep its first two bits
         Ë  # Check whether they are equal
          è # Use that to (0-based) index into the pair
J           # Join all three strings on the stack together
            # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why „€—€ƒ is "or and".

Bash, 40 bytes

a=({X,,N,XN}OR {N,}AND)
echo ${a[1$1%6]}

Try it online!

Port of my Zsh port of l4m2's answer. Prefixes the bitstring with a 1 to ensure it isn't interpreted as octal, which means the array entries/equivalence classes shift.

AWK, 61 59 bytes

$1==$4{$3="X"}$1{$4="N"}$5=$1-$2?"OR":"AND",gsub("[01 ]",z)

Attempt This Online!

The input comes with spaces, e.g.

0 0 0 1
1 1 1 0
0 1 1 1
1 0 0 0
0 1 1 0
1 0 0 1

produces:

AND
NAND
OR
NOR
XOR
XNOR

Explanation:

Google Sheets, 48 bytes

=mid("NANDAND XOR OR  NOR XNOR",1+4*mod(A1,6),4)

Put the bits as a text string in cell A1 and the formula in cell B1.

screenshot

Google Sheets, 50 48 bytes

=if(A1=D1,"X",)&if(A1,"N",)&if(A1=B1,"AND","OR")

Same score as doubleunary's lookup table. Thanks to doubleunary for a suggestion saving 2 bytes. This is my first time trying to code golf in google sheets, so I may have missed something else.

The 4 inputs should be in A1, B1, C1, D1, formula in E1.

screenshot of output in Google Sheets

Uiua, 25 bytes

⊂⊙⨬"OR""AND"▽⊓⊟"XN"⊃⤚𝄐𝄐==

Try it: Uiua pad. This is inspired by Neil's solution in Charcoal.

Uiua, 31 bytes

⊡◿6⋕⊙{⟜↘₁"NAND"⊂@X.⍥₂⊸↘₁"XNOR"}

Try it: Uiua pad. This is a port of l4m2's smart JavaScript solution, using some nice tricks to write the array shorter in Uiua.

The array needs to be in the order {"NAND" "AND" "XOR" "OR" "NOR" "XNOR"}, so:

Zsh, 37 bytes

Port of l4m2's answer, with brace expansions to shorten it.

Would require tweaks for Bash, since bash interprets 0* strings as octal by default.

a=({N,}AND {X,,N,XN}OR)
<<<$a[1+$1%6]

Try it online!

Common Lisp, 51 bytes

(princ(elt'(NAND AND XOR OR NOR XNOR)(mod(read)6)))

Try it online!

Port of l4m2's Javascript answer. It takes input from STDIN and outputs to STDOUT, since that seemed to be shorter than writing a lambda. Also, symbols are used instead of strings.

Perl 5 -pl, 49 bytes

$_=(XOR,OR,NOR,XNOR,AND,(0)x3,NAND)[-6+oct"0b$_"]

Try it online!

C, 48 45 bytes

char*f(x){return"XOR\0NAND\0XNOR"+(18-x)%12;}

Try it online!

Takes an integer.

Makes use of the properties of C's null-terminated strings: they can overlap if one is a suffix of another, and because they are represented by pointers, adding to the pointer shifts the starting point.

R, 149 bytes

`-`=\(p)\(...)!p(...)
\(x)names(which(unlist(lapply(c(AND=`&`,OR=`|`,XOR=xor,NAND=-`&`,NOR=-`|`,XNOR=-xor),\(o)all(o(rep(0:1,2),rep(0:1,e=2))==x)))))

Attempt This Online!

Checks a named list of first-class functions for one that gives the matching results.

Charcoal, 18 bytes

×X⁼θε×NIθ≡θηAND¦OR

Try it online! Link is to verbose version of code. Takes input as four space or newline separated bits. Explanation:

×X⁼θε

If the first and last bits are the same then output an X.

×NIθ

If the first bit is a 1 then output an N. (1 byte could be saved by requiring input in JSON format, which would make the Cast unnecessary.)

≡θηAND¦OR

If the first two bits are the same then output AND otherwise output OR.

brainfuck, 132 bytes

-[--->+<]>[>,]<<<<[->->->-<<<]>>>[>]<<<<[+++.--->]<------->>>>[>]<-[<<<[>]<.>>[>]]<[[<]<+.+++.<]<[>>]<<[>>----[----<+>]<++.<.>+++.>]

Try it online!

Expects input as a string of 4 ascii digits (terminated with zero byte.) The code starts by generating 255/3=85 (ASCII U), then takes the four inputs, and subtracts the first from the rest. This gives the following memory status. It prints an X if the last cell is zero, an N if the last nonzero is negative, followed by OR if the cell next to it is nonzero (or AND if it is zero.)

0001 -> AND       0  85  0  0  0  1
1110 -> NAND      0  85  0  0  0 -1  
0111 -> OR        0  85  0  1  1  1
1000 -> NOR       0  85  0 -1 -1 -1
0110 -> XOR       0  85  0  1  1  0
1001 -> XNOR      0  85  0 -1 -1  0     

Developed at https://minond.xyz/brainfuck/ . Brief comments below will be improved later.

-[--->+<]         Countdown cell 0 to setup 255/3=85 in cell 1
>[>,]<<<<         Take input in cells 2~5 & move to cell 2 
[->->->-<<<]>>>   Decrement all inputs until cell 2 = 0
[>]<<<<[+++.--->] If cell 5 = 0 print X and end in cell 2
<------->>>>[>]<  Prepare cell 1 to print N and move to last nonzero cell
-[<<<[>]<.>>[>]]  Decrement last nonzero cell and If still nonzero it must be negative so print N  
<[[<]<+.+++.<]    If cell to the left is nonzero print OR and leave pointer to left of all data
<[>>]<<           Search to the left of the current cell for the cell containing N
[>>               If found generate the ASCII for A 
 ----[----<+>]<++.(256-4)/4+2=65 and print it 
<.>+++.>]         Followed by ND

Vim, 70 bytes

llx:s/001/AND
:s/010/XOR
:s/011/OR
:s/100/NOR
:s/101/XNOR
:s/110/NAND

Try it online!

Port of this answer made by Unrelated String.

Explanation: remove the third character, then make the appropriate substitutions. Probably the simplest answer.

Jelly, 22 bytes

“u{nµỤẈiBÞ]Ṛ[)®Æ8Ẇ»Ḳị@

Try it online!

Direct port of l4m2's decimal lookup table. Jelly doesn't have any such conversion from string to decimal that can handle leading zeroes as desired, so if decimal input isn't acceptable, add +1 byte for a at the end taking list input. A permutation index or other magic formula might be able to make exploiting the structure of the output more competitive, but I've got a lunch to eat, and I'm mostly just disappointed that this beats:

Jelly, 24 bytes

^\Ḅ^1‘ị⁾XNŒPp@“AND“OR”¤Ṛ

Try it online!

Takes input as a flat list of truth values.

^\                          Scan by XOR. Since the middle two bits are always equal,
^\Ḅ  ‘ị                     bit 1 is copied to bit 3, and thus affects 2 and 4 equally.
  Ḅ                         Convert to binary.
   ^1                       XOR with 1 (i.e. flip bit 4).
     ‘ị               ¤     0-index (mod 8) into:
              “AND“OR”      ["AND", "OR"]'s
            p@              ordered Cartesian product with
       ⁾XNŒP                the powerset of "XN".
                       Ṛ    Reverse the obtained pair (which is implicitly smash-printed).

JavaScript (ES6), 45 bytes

A solution without a lookup table.

Expects a 4-character binary string.

x=>"XN".slice(x%9%2,1-x&9)+(x%6<2?"AND":"OR")

Try it online!

Jelly, 33 bytes

“yy⁺ṗ+qƈ¶Ƒạ~×þɱL³Ð»Ḳ
“⁷4⁶’Bs4i³ị¢

Try it online!

I'll think of a way to golf that... later.

JavaScript (Node.js), 43 bytes

x=>'NAND1AND1XOR1OR1NOR1XNOR'.split(1)[x%6]

Try it online!

-3 bytes tsh

Trivial. (if) Porting Unrelated String would make it longer

APL+WIN, 56 bytes

Prompts for a vector of ones and zeros:

('AND' 'NAND' 'OR' 'NOR' 'XOR' 'XNOR')['147869'⍳⍕10|2⊥⎕]

Try it online! Thanks to Dyalog Classic

Retina 0.8.2, 41 39 bytes

(.)..\1
X$&
1...
N$&
(.)\1..
AND
\d+
OR

Try it online! Link includes test cases. Explanation:

(.)..\1
X$&

Prefix X if the first and last digits are the same.

1...
N$&

Prefix N to the first digit if it is a 1.

(.)\1..
AND

Replace the digits with AND if the first and second are the same.

\d+
OR

Otherwise replace the digits with OR.

Python, 46 44 bytes

lambda a,b,_,d:'XN'[a^d:-~a]+'AONRD'[a^b::2]

Attempt This Online!

-2 thanks to dingledooper

Anonymous function taking each truth value as a separate argument. Returns the concatenation of:

'XN'[a^d: ... ]

X, if the output for 11 is 0 (flipped if the output for 00 is 1);

'XN'[ ... :-~a]

N, if the output for 00 is 1;

'AONRD'[a^b::2]

and either AND or OR, depending on the output for 01 (flipped if the output for 00 is 1), by choosing either the even- or odd-indexed elements of AONRD.