这个挑战是要唤起我们通常是错误的 mod A. Alex A.的精神。
假设您有一个名为Alex的朋友,他需要有关基本逻辑和数学(特别是数学等效性)的帮助。
他为您提供了以下形式的方程式列表,[variable] = [variable]
其中a [variable]
始终是单个大写字母A到Z(不是小写字母,数字,也没有其他内容)。列表中每行只有一个方程,只说了一行therefore
。
上面的所有方程式therefore
都是前提,假设事实成立。下面的所有等式therefore
都是未经验证的命题,这是Alex试图从前提推论得出的事实,它们可能是正确的也可能不是正确的。
例如,在此等式列表中,单个结论命题A = C
恰好是正确的:
A = B
B = C
therefore
A = C
告诉亚历克斯,如果他的所有命题在逻辑上都遵循给定前提,这是您的工作。也就是说,您需要在结论中告诉Alex他是对还是错。
编写一个程序/函数,该程序/函数接受所描述的一系列方程式的字符串并打印/返回
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
therefore\nTABS < SPACES
->Alex is right
Alex is wrong
验证所有测试用例。