# 评估不平等链

17

`3<=4!=9>3==3`

`(3<=4) and (4!=9) and (9>3) and (3==3)`

``````==   equals
!=   does not equal
>    is greater than
>=   is greater than or equal to
<    is less than
<=   is less than or equal to
``````

``````3<=4!=9>3==3
True

3<=4!=4
False

5>5
False

8==8<9>0!=2>=1
True
``````

FUZxxl 2015年

@FUZxxl您不能。
xnor

7

# Ruby，71 +1 = 72

``````p (0..99).none?{|i|~/#{a=i%10}(#{%w/!=|. <?=* >?=*/[a<=>b=i/10]})#{b}/}
``````

• 通过从0到99循环并提取10s和1s数字，我们得到所有可能的数字对。
• 我们所做的唯一实际比较是`a<=>b`，它返回-1,0或1表示小于，等于或大于。这些都切成三串数组的不同元素，找到不匹配的正则表达式。

xnor 2015年

6

# Perl，82岁

``\$_=<>;(\$'<=>\$&)-61+ord\$1&&(\$2&&\$&==\$')^('\$'lt\$1)&&die"\n"while/\d(.)(=?)/g;print 1``

while循环遍历与regex匹配的字符串`\d(.)(=?)`。然后，变量`\$1``\$2`对应于运算符的字符，特殊变量`\$&``\$'`在数值上下文中将充当两个操作数。将操作数与`<=>`运算符的第一个字符进行比较，并将结果与​​运算符的第一个字符进行匹配。然后，平等和不平等被专门处理。

4

# CJam，60个字节

``````q_A,sSer_S%@@-(])1\@z{~:X\:^i['=")<"P"(>"P'<'^'>PPP]=~e&X}/;
``````

### 说明

``````q               "Read the input";
_A,sSer         "Copy the input and replace each digit with a space";
_S%             "Split around spaces to obtain the operation list";
@@-             "Remove operations from the input to obtain the operand list";
(])1\@z         "Remove the first operand from the list to be the initial left
operand, initialize the result to 1 (true), and pair up the
operations and remaining operands";
{               "For each operation-operand pair:";
~:X             "Let the operand be the right operand of this operation";
\:^i            "Hash the operation (bitwise XOR of all characters)";
[               "Begin cases:";
'=              " 0: Equals";
")<"            " 1: Less than or equal to";
P               " 2: (Invalid)";
"(>"            " 3: Greater than or equal to";
P               " 4: (Invalid)";
'<              " 5: Less than";
'^              " 6: Bitwise XOR (stand-in for not equal to)";
'>              " 7: Greater than";
P               " 8: (Invalid)";
P               " 9: (Invalid)";
P               "10: (Invalid)";
]=~             "Execute the case selected by the operation hash modulo 11";
e&              "Compute the logical AND of the result and the value produced
by this operation to be the new result";
X               "Let the right operand be the new left operand";
}/              "End for each";
;               "Clean up and implicitly print result";
``````

4

# 的JavaScript（ES6）110 116

``F=x=>(l='',[for(c of x)10-c?(v=!l||v&&(o<'<'?l!=c:(o[1]&&c==l)||(o<'='?l<c:o<'>'?c==l:l>c)),l=c,o=''):o+=c],v)``

``````;['3<=4!=9>3==3','3<=4!=4','5>5','8==8<9>0!=2>=1']
.forEach(s=>console.log(s,F(s)))``````

3 <= 4！= 9> 3 == 3是
3 <= 4！= 4否
5> 5否
8 == 8 <9> 0！= 2> = 1是

3

``````r a=read[a]::Int
l"!"=(/=)
l"="=(==)
l">"=(>=)
l"<"=(<=)
k">"=(>)
k"<"=(<)
[]#_=1<2
(a:'=':b:c)#i=l[a]i(r b)&&c#r b
(a:b:c)#i=k[a]i(r b)&&c#r b
f(h:t)=t#r h
``````

``````f "3<=4!=9>3==3"        -> True
f "3<=4!=4"             -> False
f "5>5"                 -> False
f "8==8<9>0!=2>=1"      -> True
``````

``````digitToInt d = read [d] :: Int

lookup2 "!" = (/=)
lookup2 "=" = (==)
lookup2 ">" = (>=)
lookup2 "<" = (<=)

lookup1 ">" = (>)
lookup1 "<" = (<)

eval []              _ = True
eval (op:'=':d:rest) i = lookup2 [op] i (digitToInt d) && eval rest (digitToInt d)
eval (op:d:rest)     i = lookup1 [op] i (digitToInt d) && eval rest (digitToInt d)

evalChain (hd:rest) = eval rest (digitToInt hd)
``````

`eval`接受两个参数：要解析的字符串（始终从比较运算符开始）和一个数字`i`，该数字是用于比较的左参数（在上一轮中是右参数）。如果运算符是`lookup2`两个字符的运算符（仅检查1st char，因为2nd始终为`=`），则返回该运算符，`lookup1`如果它只是单个字符，则返回该运算符。`eval`递归地调用自身，并将所有返回值与逻辑和相结合`&&`

3

# 普通Lisp- 300185 169 165

``````(lambda(s)(loop for(a o b)on(mapcar'read-from-string(cdr(ppcre:split"([0-9]+)"s :with-registers-p t)))by #'cddr always(if o(funcall(case o(=='=)(!='/=)(t o))a b)t)))
``````

# 例

``````(mapcar (lambda(s) ...)
'("2<=3<=6>2<10!=3"
"3<=4!=9>3==3"
"3<=4!=4"
"5>5"
"8==8<9>0!=2>=1"))
=> (T T NIL NIL T)
``````

# 说明

``````(lambda (s)
(loop for (a o b) on (mapcar
(cdr
(cl-ppcre:split "([0-9]+)" s
:with-registers-p t))) by #'cddr
always (if o
(funcall (case o
(== '=)
(!= '/=)
(t o))
a b)
t)))
``````
• `ppcre:split`按数字分割；例如：

``````(ppcre:split "([0-9]+)" "2<=3<=6>2<10!=3" :with-registers-p t)
=> ("" "2" "<=" "3" "<=" "6" ">" "2" "<" "10" "!=" "3")
``````

请注意第一个空字符串，该字符串将使用丢弃 `cdr`

• 映射`read-from-string`到此列表`read`将为每个字符串调用该函数，该函数返回符号和数字。

• `loop for (a op b) on '(3 < 5 > 2) by #'cddr`遍历该列表通过的工序2个，因此结合`a``op``b`如下，对于每个连续的传递。

``````a  op  b
----------
3  <    5
5  >    2
2  nil  nil
``````
• `always`检查下一个表达式是否始终为真：运算符为`nil`（请参见上文）或比较结果成立（请参见下文）。

• `case`选择一个共Lisp的比较函数，根据先前读取的符号; 由于某些运算符在Lisp和给定的语言中是相同的，因此我们可以`o`在默认情况下简单地返回。

1

# Python 2中，95 102

``````t=1
n=o=3
for c in map(ord,raw_input()):
o+=c
if 47<c<58:t&=627>>(o-c+3*cmp(n,c))%13;n=c;o=0
print t
``````

xnor

@xnor糟糕。已更正。
DLosc

1

# Javascript 101字节

``````F=(s,i=0,l=o="")=>[...s].every(c=>c>=0?[l^c,l==c,,l<c,l>c,l<=c,,l>=c]["!==<><=>=".search(o,l=c,o="")]:o+=c,l=o="")

console.log(F("3<=4!=9>3==3")==true)
console.log(F("3<=4!=4")==false)
console.log(F("5>5")==false)
console.log(F("8==8<9>0!=2>=1")==true)``````

0

# Java 8，283字节

``````s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;)if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))|(a[i].equals("!=")&x==y)|(a[i].equals(">")&x<=y)|(a[i].equals(">=")&x<y)|(a[i].equals("<")&x>=y)|(a[i].equals("<=")&x>y))r--;return r>0;}
``````

``````s->{                            // Method with String parameter and boolean return-type
String[]a=s.split("\\d"),     //  All the inequalities
b=s.split("\\D+");    //  All the digits
int i=0,                      //  Index-integer (starting at 0)
r=1,                      //  Flag integer for the result, starting at 1
x,y;                      //  Temp integer `x` and `y`
for(;i<a.length-1;)           //  Loop from 0 to the length - 1
if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))
//   If "==" and `x` and `y` as int are not equal:
|(a[i].equals("!=")&x==y)  //   Or "!=" and `x` and `y` are equal
|(a[i].equals(">")&x<=y)   //   Or ">" and `x` is smaller or equal to `y`
|(a[i].equals(">=")&x<y)   //   Or ">=" and `x` is smaller than `y`
|(a[i].equals("<")&x>=y)   //   Or "<" and `x` is larger or equal to `y`
|(a[i].equals("<=")&x>y))  //   Or "<=" and `x` is larger than `y`
r--;                        //    Decrease `r` by 1
//  End of loop (implicit / single-line body)
return r>0;                   //  Return if `r` is still 1
}                               // End of method
``````