# 亚历克斯有时候是对的

50

``````A = B
B = C
therefore
A = C
``````

``````Alex is right
``````

``````Alex is wrong
``````

• 变量始终等于自己。例如

``````B = A
therefore
A = A
X = X
``````

结果`Alex is right`

• 关系未知的变量不能假定相等。例如

``````P = Q
therefore
E = R
``````

结果`Alex is wrong`

• 如果之后没有方程式，`therefore`则结论是虚空的。例如

``````D = C
therefore``````

``therefore``

都导致`Alex is right`

• 如果之前没有方程式，`therefore`则只能推断出自等式。例如

``````therefore
R = R
``````

结果`Alex is right`，但

``````therefore
R = W
``````

结果`Alex is wrong`

## 更多例子

``````A = B
C = D
therefore
A = C

A = L
E = X
A = I
S = W
R = O
N = G
therefore
G = N
L = I
R = O
S = A
X = X
X = E

D = K
D = Q
L = P
O = L
M = O
therefore
K = L

A = B
therefore
B = C

Z = A
S = S
therefore
A = Z
A = A
S = A
A = S
Z = A
Z = A

K = L
K = X
therefore
X = P
L = X
L = P

therefore
A = B
B = C
A = C

therefore
A = A
B = B
C = C
D = D
E = E
F = F
G = G
H = H
I = I
J = J
K = K
T = I
L = L
M = M
N = N
O = O
P = P
Q = Q
R = R
S = S
T = T
U = U
V = V
W = W
X = X
Y = Y
Z = Z

A = B
B = C
C = D
D = E
E = F
F = G
G = H
H = I
I = J
J = K
K = L
L = M
M = N
N = O
O = P
P = O
Q = R
R = S
S = T
T = U
U = V
V = W
W = X
X = Y
Y = Z
therefore
A = Z

therefore
C = D
T = Y
A = Z

P = Q
therefore
E = R

therefore
R = W``````

``````H = J
therefore
J = H

K = L
K = X
therefore
L = X

C = B
B = A
therefore
A = B

K = L
K = X
K = P
therefore
L = X
L = P
X = P

A = Y
Y = Q
Q = O
therefore
O = Y
O = A

C = C
therefore
C = C

A = B
B = A
therefore
A = B
B = A

A = B
B = C
C = D
therefore
A = A
A = B
A = C
A = D
B = A
B = B
B = C
B = D
C = A
C = B
C = C
C = D
D = A
D = B
D = C
D = D

therefore
A = A
B = B
C = C
D = D
E = E
F = F
G = G
H = H
I = I
J = J
K = K
L = L
M = M
N = N
O = O
P = P
Q = Q
R = R
S = S
T = T
U = U
V = V
W = W
X = X
Y = Y
Z = Z

D = I
F = H
J = M
therefore
M = J
D = I
H = F

A = B
B = C
C = D
D = E
E = F
F = G
G = H
H = I
I = J
J = K
K = L
L = M
M = N
N = O
O = P
P = Q
Q = R
R = S
S = T
T = U
U = V
V = W
W = X
X = Y
Y = Z
therefore
Z = A
F = R
G = I
W = L

A = B
B = C
therefore
A = C

B = A
therefore
A = A
X = X

P = P
C = G
M = C
therefore

D = C
therefore

therefore

therefore
R = R``````

42
PHP，13个字节`Alex is wrong`验证所有测试用例。

19

7
`therefore\nTABS < SPACES`->`Alex is right`

7

azz

18

# 果酱（49）

``````"Alex is "qN%S{f{)er}(_el-}h;{)#},"wrong""right"?
``````

3字节，感谢jimmy23013 :)

``````"Alex is "    first push the part we know
qN%           read the input and split into lines
S             push a space (initial no-op replacement string, see below)
{…}h          do-while
f{…}        for each line and the replacement string
)         take out the last character
er        replace the remaining character(s) with that character
(           afterwards, take out the first line
_el         duplicate and convert to lowercase
-           remove all the resulting characters from the line
this removes all lowercase letters and non-letters
"X = Y" becomes "XY" (new replacement string)
and "therefore" becomes "" (ending the loop)
this is the loop condition and is left on the stack every time
;             after the loop, pop the empty string (from "therefore")
{…},          filter the remaining (conclusion) lines using the condition block
)           take out the last character
#           find its index in the remaining string
this is 0 (false) iff the first character is the same as the last
afterwards, we have an array of lines with non-equal variables
"wrong"       push "wrong"
"right"       push "right"
?             choose "wrong" if the array was not empty, else choose "right"
``````

``````"Alex is "26,:A;{:i{{_A=_@-}g}%\$~}:F;0q"= "-'t/Nf%~\{A\Ft:A;}/1>{F=}%-"right""wrong"?
``````

1
`"Alex is "qN%S{f{)er}(_el-}h;{)#},"wrong""right"?`
jimmy23013 2015年

1

1

`Alex is * wrong * right * ?`

32

# 红宝石，80 76 + 2 = 78

``````gsub\$1,\$2%p=\$`[/e/]while~/(.) = (?!\1)(.)/
\$_="Alex is #{p ?:wrong: :right}"
``````

``````\$`[/e/]
``````

15

Alex A.

Ventero

12

# CJam，83 75 68 67 64字节

``````"Alex is "q_elN--N/:\$La/~{)-},\{__m*{:&},::^|}5*-"wrong""right"?
``````

## 说明

（有点过时。）

``````"Alex is " e# Push the string.
_elN-      e# Make a copy, convert to lower case, remove linefeeds. This gives us a string
e# with all the characters we don't want from the input.
-          e# Remove them from the input. This leaves two upper-case letters on each line
e# and an empty line between premises and conclusions.
N/         e# Split into lines.
La/        e# Split around the empty line.
~          e# Dump both halves on the stack.
{)-},      e# Remove any "A = A"-type equalities from the conclusions.
\          e# Swap with the premises.
{          e# Extend the premises 5 times...
_Wf%     e#   Duplicate the premises and reverse each one, because = is symmetric.
|        e#   Set union with the original premises.
__m*     e#   Make two copies and get an array of every possible pair of premises.
{:&},    e#   Select those which have at least one character in common.
::^      e#   For each such pair, take the mutual set difference, i.e. those characters
e#   that are in only one of the strings.
|        e#   Set union with the original premises.
}5*
-          e# Remove all the equalities we've obtained from the conclusions. If all
e# conclusions were valid, the result will now be a empty array, which is falsy.
!          e# Logical not.
"wrong""right"?
e# Select "wrong" or "right", respectively.
``````

user2357112

@ user2357112我认为它们应该在两个方向上生成，因为第一步将输入的所有反向添加（或者在进一步研究的版本中，我将所有前提和结论均等排序）。
Martin Ender

user2357112 2015年

@ user2357112由于我正在处理整个笛卡尔乘积，因此我将获得两种顺序的每一对相等性，这将导致得出结论的两种顺序（我需要显式反转或对初始输入进行排序的唯一原因是原始前提不一定是在此过程中生成的，因此不会因采用笛卡尔乘积的集合差异而将它们反转。

6

## R，183192字节

``````i=grep("t",z<-scan(,"",,,"\n"))
``````

``````lines = scan(, what = "", sep = "\n")
therefore_idx = grep("therefore", lines)
setup = paste(LETTERS, "=", 1:26)
premises = sample(rep(head(lines, therefore_idx - 1), 1000))
propositions = paste(c(TRUE, sub("=", "==", tail(lines, -therefore_idx))), collapse = "&")
things_to_evaluate = c(setup, premises, propositions)
boolean_result = eval(parse(text = things_to_evaluate))
cat("Alex is", if (boolean_result) "right" else "wrong")
``````

``````A = B
B = C
therefore
A = C
B = C
``````

``````A = 1
B = 2
...
Z = 26
``````

``````A = B
B = C
``````

``````TRUE & A == B & B == C
``````

3

user2357112

flodel，2015年

flodel 2015年

5

``````import Data.Equivalence.Persistent
c l=equate(l!!0)\$last l
r=foldr(c)\$emptyEquivalence('A','Z')
l#r=equiv r(l!!0)\$last l
f x|(h,_:t)<-span((<'t').head)\$lines x="Alex is "++if all(#r h)t then"right"else"wrong"
``````

``````*Main> f "A = B\nB = C\ntherefore\nA = C"
"Alex is right"

*Main> f "A = B\nB = D\ntherefore\nA = C"
"Alex is wrong"
``````

3

# Mathematica，182

``````f[s_]:="Alex is "<>If[True===And@@Simplify[#2,#1]&@@(StringSplit[s,"\n"]/.{a___,"therefore",b___}:>StringSplit/@{{a},{b}}/.{x_,_,y_}:>Symbol[x<>"\$"]==Symbol[y<>"\$"]),"right","wrong"]
``````

``````In[]:= f["A = B
B = C
therefore
A = C"]
Out[]= Alex is right

In[]:= f["D = K
D = Q
L = P
O = L
M = O
therefore
K = L"]
Out[]= Alex is wrong
``````

LegionMammal978

LegionMammal978

`a__`并且`b__`即使前提，命题或两者都为空也不会起作用

3

# 视网膜，90字节

``````s+`^(.) = (.)(.*)\1
\$1 = \$2\$3\$2
)`^. .+\n
<empty>
^.+|(.) = \1
<empty>
^\n*\$
right
^[^r]+
wrong
^
Alex is
``````

3

# Python 2，264字节

mbomb007已经有了一个出色的Python 3答案。这个答案从那个人那里窃取了（特别是“ Alex is wrriognhgt”把戏）。

``````def a(s):
d={C:set(C)for C in map(chr,range(65,91))};p,c=s.split('t');c,p=[x.split('\n')for x in[c[9:],p]]
for u in p[:-1]:
g,h=u[::4];y=d[g]|d[h]
for v in y:
for w in y:d[v]|=d[w];d[w]|=d[v]
print'Alex is','wrriognhgt'[all(uin d[u]for u in c if u)::2]``````

（为了节省字节，此答案将空格和制表符混合使用，这在Python 2中是合法的。）

``d={C:set(C)for C in map(``

``d={C:C for C in map(``

``````A = B
A = B
therefore
B = A``````

``````{A:A, B:B}      (start)
{A:AA, B:B}     (d[A] += d[A])
{A:AAAA, B:B}     (d[A] += d[A])``````

``````{A:AAAA, B:B}     (start)
{A:AAAAB, B:B}    (d[A] += d[B])
{A:AAAAB, B:BAAAAB}   (d[B] += d[A])``````

``````{A:AAAAB, B:BAAAAB}   (start)
{A:AAAAB, B:BAAAABAAAAB}     (d[B] += d[A])
{A:AAAABBAAAABAAAAB, B:BAAAABAAAAB}     (d[A] += d[B])``````

`v=B, w=B`

``````{A:AAAABBAAAABAAAAB, B:BAAAABAAAAB}     (start)
{A:AAAABBAAAABAAAAB, B:BAAAABAAAABBAAAABAAAAB}     (d[B] += d[B])
{A:AAAABBAAAABAAAAB, B:BAAAABAAAABBAAAABAAAABBAAAABAAAABBAAAABAAAAB}     (d[B] += d[B])``````

mbomb007'2015-10-26

1
@ mbomb007呵呵，很抱歉听到这个消息。（我确实认为您有一个很酷的方法！）由于您反对“伟大”一词，所以我用“卓越”代替。:)
mathmandan

2

# ES6，128个字节

``````r=s=>(m=/^[^e]*(.) = (?!\1)(.)/.exec(s))?r(s.replace(RegExp(m,'g'),m)):'Alex is '+(/(.) = (?!\1)/.test(s)?'wrong':'right')
``````

1

# C，240字节

``````#define V[v-65]
v;char*r[]={"wrong","right"};i=65;j;g(a){return a V^a?g(a V):a;}main(){char b;for(;i<91;++i)i V=i;while(gets(b)&&*b<99)bV=bV=bV<bV?bV:bV;while(gets(b))j|=g(*b)^g(b);printf("Alex is %s\n",r[!j]);}``````

``````// Anything before `V` becomes an index into `v`, offset by -'A'.
#define V [v-65]
int v;
char* r[] = {"wrong", "right"};
int i=65;
int j;
// Finds a set identifier for a by recursing until some index points to itself.
int g(int a) {
return a V ^ a
? g(a V)
: a;
}
int main() {
char b;
// Initialize all entries to point to themselves.
for(; i < 91; ++i)
i V = i;
// For each premise "A = B", set the entries for A and B to point to the
// smaller of their current values. This exits after reading "therefore"
// as 't' > 99.
while (gets(b) && *b < 99)
bV = bV = bV < bV
? bV
: bV;
// For each conclusion "A = B", OR j with non-zero if the set identifiers
// for A and B are different.
while (gets(b))
j |= g(*b) ^ g(b);
printf("Alex is %s\n", r[!j]);
}``````

# 180字节

``v;*V=v-65;char*r[]={"wrong","right"};i;j;main(){char b;for(;i<26;++i)v[i]=i;while(gets(b)&&*b<99)V[b]=V[*b];while(gets(b))j|=V[*b]^V[b];printf("Alex is %s\n",r[!j]);}``

A = B
C = B

A = C

1

# 05AB1E，32 字节

``````…±º€ˆ „–Ñƒ©#|€á[ćD.l#`:}\€ËPè«.ª
``````

``````…±º€ˆ      # Push dictionary string "alex is "
„–Ñƒ©      # Push dictionary string "wrong right"
#     # Split by spaces: ["wrong","right"]
|          # Push all input-lines as list
€à        # Only leave the letters of each line
[       # Start an infinite loop:
ć      #  Extract the head of the list; pop and push remainder-list and head separately
.l   #  If it's a lowercase string:
#  #   Stop the infinite loop
`      #  Push both letters in the string to the stack
:     #  Replace all these letters in the remainder-list
}\        # After the infinite loop: discard the duplicated "therefore"
€       # For each letter-pair in the remainder list of condition-lines:
Ë      #  Check if both letters are equal (1 if truhy; 0 if falsey)
P       # Check if everything was truthy by taking the product
è      # Use this to index into the earlier ["wrong","right"]-list
«     # Append it to the "alex is " string
.ª   # Sentence capitalize it
# (after which the result is output implicitly)``````

0

# bash + awk + SWI-Prolog，167字节

``head -n1 <(awk '/therefore/{s=1;next};{if(s)print"?=("\$1","\$3")";else print};END{print"write(\"Alex is right\");write(\"Alex is wrong\"). halt."}' -|paste -sd ,|swipl)``