# Tag Info

0

Scala, Score: ~26.14 (183 bytes, 7 ops) i=>("OR"+i split "(?<=\\d)").foldLeft(false){(b,o)=>val s=o.replace("NOT","") val c=(s!=o)^(o.last>48) (s.count(_==78)==1)^(if(s contains 65)!(b&c)else if(s contains 88)b^c else b|c)} Try it online! The operators are uppercase (whitespace doesn't matter), and ...

0

brainfuck, 130 bytes / 1 operator = 130 +>>+<,[------------------------------------------------[<->[-]]<[>>[-]<<-]><+>,]>++++++++++++++++++++++++++++++++++++++++++++++++. Try it online! Link is for a readable, commented version. Only implements AND. Although technically all it does is print 1 unless there is a 0 in ...

0

Haskell, $225 \div 4 = 56.25$ b(_:'A':'0':s)=b('0':s) b(c:'A':_:s)=b(c:s) b(_:'O':'1':s)=b('1':s) b(c:'O':_:s)=b(c:s) b('N':'0':s)=b('1':s) b('N':_:s)=b('0':s) b('0':'X':'0':s)=b('0':s) b('1':'X':'1':s)=b('0':s) b(_:'X':_:s)=b('1':s) b x=x f=(b.map(!!0)) Defines a function f, which given a list of the format ["1","AND","0"] ...

0

Japt v2.0a0, 36 bytes ÷ 7 ≈ 5.14 e/..*?\d/@1&#e4#÷0953÷2pXn36 %873%34 Try it Try all testcases Try all possible sub-expressions A direct port of @Arnauld's answer to Japt Explanation e/..*?\d/@1&#e4#÷0953÷2pXn36 %873%34 e // Repeatedly replace /..*?\d/ // the regex /..*?\d/g with ...

1

JavaScript (ES7), 77 bytes / 7 operators = 11 Expects a string with no separator, such as "1NORNOT0". f=s=>1/s?s:f(s.replace(/..*?\d/,s=>10142470953/2**(parseInt(s,36)%873%34)&1)) Try it online! Or try all possible sub-expressions. How? We use a recursive function to simplify the input string s until we get a single digit. When this ...

1

sed, 8 bytes ÷ 1 = 8 /0/c0 c1 Try it online! Implements only and. Explanation /0/c0 # Set contents of line to 0 if line contains 0 c1 # Otherwise set contents to 1

1

SimpleTemplate, 361 bytes ÷ 4 operators = 90.25 It is a very big piece of code, but was very challenging! {@fnP S}{@fnT.AND a,b}{@ifa}{@ifa is equalb}{@return1}{@/}{@/}{@return"0"}{@/}{@fnT.OR a,b}{@incbyb a}{@ifa}{@return1}{@/}{@return"0"}{@/}{@fnT.XOR a,b}{@ifa is equalb}{@return1}{@/}{@return"0"}{@/}{@whileS matches"@([...

0

JavaScript (V8), 141 bytes ÷ 7 operators, score 20.14 f=i=>'01'[i]||f(i.replace(/NOT./,n=>'10'[n]).replace(/(.)(..)\D*(.)/,(_,a,o,b)=>({AN:a&b,OR:a|b,XO:a^b,NA:a&b^1,NO:(a|b)^1,XN:a^b^1})[o])) Try it online! Takes input as a string with capitalised operators and no padding, like 0AND1OR0. Recursively calculates the next value based on ...

2

Perl 5, 86 bytes / 7 operators = 12.29 s/not/!/g;s/\d//;$\=1*$1;$\=eval"$\ $_"=~s/(.*?[^a])n(.*)/!($1$2)/r for/.*?\d/g}{$\|=0 Try it online! Perl 5, 9 bytes / 3 operators (or, xor, not) = 3 $_=0|eval Try it online! 0 Wolfram Language (Mathematica), 62 bytes ÷ 6 = 10.33 Boole@ToExpression[Capitalize@#~StringRiffle~"~"]/.a:0|1:>a>0& Try it online! Pure function. Takes a list of lowercase strings as input and returns 0 or 1 as output. Supports every operation except NOT. Wolfram Language (Mathematica), 87 bytes ÷ 7 = 12.43 Boole@ToExpression@... 3 FEU, 33 bytes, 2 operations, score 16.5 m/NOT 0/1/NOT 1/0/.*1.*/1/[^1]+/0 Try it online! Implements NOT and OR 3 Japt, 1 byte ÷ 1 = 1 e Try it online! Implements only and. Works by checking if every element in the input has a truthy value. 12 Pyth, 1 byte ÷ 2 = 0.5 v Try it online! This works for and and not. Works by evaluating the input as python code 2 APL (Dyalog Extended), 2 bytes ÷ 1 = 2 ~⍲ Try it online! ⍲ (nand) returns 1 if and only if argument has a 0 anywhere (it ignores all other data) ~ negates that APL (dzaima/APL), 2 bytes ÷ 1 = 2 1∊ Try it online! Simply asks is there any 1 in the argument? 9 Python 3, 16 4 bytes / 2 = 2 score eval Try it online! This works for and and not in any combinations. It partially works for or but only when not used in conjunction with and in certain cases due to operator precedence in Python. As such cases exist, my official score will only be divided by two (if half-points are allowed, this could maybe be divided by ... 4 APL (Dyalog Unicode), 43 36 bytes ÷ 6 = 6 Thank you user41805 for the idea of combining definitions that are negations of each other and to tsh for noticing stray spaces. DNAN←~DNA←∧ RON←~RO←∨ ROX←~RONX←= ⍎⌽ Try it online! Since APL is right-to-left, we define the functions with reversed names, then reverse the expression (⌽) and execute it (⍎). APL (... 18 Python, 3 bytes ÷ 1 op = score 3 min Try it online! Implements AND, with inputs like ["1", "AND", "0", "AND", "0"]. Simply takes the smallest string value, which is "0" if present and "1" otherwise. Since "AND" is later alphabetically, it can be ignored. Another solution is all,... 2 Retina 0.8.2, 84 bytes, score 12 NOT0 1 NOT1 0 ^(0A|1NO|(0NA|1O))[A-Z]+.$#2 }^(1A|0O|0XO|1XN)[A-Z]+ }^.[A-Z]+ NOT Try it online! Link includes test suite that deletes spaces from the input for the convenience of the user. Explanation: NOT0 1 NOT1 0 Handle the NOT operator. ^(0A|1NO|(0NA|1O))[A-Z]+. $#2 0 AND and 1 NOR are always 0, while 0 NAND and 1 ... 7 Python 2, score 15.714 (132 ... 114 110 bytes, 7 operators) Input is a single string with lowercase operators. b=c=d=49 for a in input().replace('t ','a').split():a=hash(a);c,d=[a|d,a&d,a^d^1][b%65%3]^b%45,c;b=a print~c&1 Try it online! The code uses the following numbers produced by Python 2's hash function: +--------+----------------------+-----+-... 8 Sorry to report that the task is trivial in some language, but anyway here it is. J, 2 bytes, score 2 ÷ 1 = 2 ". Try it online! Implements any one of AND, OR, or XOR. The three are defined in the J standard library as infix functions, so calling ". (eval) on the string automagically evaluates the given expression as-is. The only problem is that J ... 7 05AB1E, score: 1 (1 byte, 1 operator) ß Input as a list of strings for each digit/operator. Implements AND. Port of @xnor's Python answer. Try it online or verify a few more test cases. Explanation: ß # Pop the (implicit) input-list and leave its minimum, # which is "0" if the input contains a "0", or "1" otherwise ... 7 JavaScript (ES6), 268 265 254 248 bytes Expects an array of strings. Returns a single linefeed-separated string. a=>a.map(o=r=s=>([[c],s,e]=s.split ,c>'m'?c>r?o[s]=1:o[e||+o[s]&&s]=0:c<'m'?o=s.split/.every(s=>o=o[s]-2?0:o[s],q=o)?o:q:o[s]=o[s]||{'..':o}))&(g=(o,i)=>[0,1].map(t=>{for(k in o)(v=o[k],t?v^1:v-2|k<S)||... 9 Python 2, 358 ... 280 277 bytes thanks to randomdude999 for -3 bytes and a bugfix. Input is a list of commands, where each command is represented by a 2-tuple as (cmd, args). Test cases can be transformed using this Retina program. K=T={} for c,a in input(): try:exec"T[a]=1|x=a<'.';if x or T[a]<2:del T[a[3*x:]]|T[a]=T.get(a,{'..':T})|E=T\nfor p in a.... 7 Bash, 133 86 bytes (for i;{$i [[ $PWD =~ , ]]||cd ->~/e }) tree --dirsfirst|sed '$d;s#[^0-Z.]# #g;1c /' -2 bytes thanks to @Dom Hastings (removing spaces around ||) -6 bytes thanks to @Dom Hastings (removing eval before $i and using # as a sed delimiter) -12 bytes thanks to @ilkkachu (combining the seds). -5 bytes thanks to @chepner (=~,$PWD and sed ...

Top 50 recent answers are included