我必须制作一个计算魔法矩阵的程序,我已经制作了??我的代码并且它可以工作,但我的置换非常慢。我需要一个更快的人可以帮助我请
这是代码:
diabolico([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P]) :-
permutar([1,14,3,16,5,12,13,15,9,10,11,6,7,2,8,4],[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P]),
A+B+C+D=:=34, E+F+G+H=:=34, I+J+K+L=:=34, M+N+O+P=:=34,
A+E+I+M=:=34, B+F+J+N=:=34, C+G+K+O=:=34, D+H+L+P=:=34,
M+B+G+L=:=34, I+N+C+H=:=34, E+J+O+D=:=34, A+F+K+P=:=34,
P+C+F+I=:=34, L+O+B+E=:=34, H+K+N+A=:=34, D+G+J+M=:=34.
permutar([],[]).
permutar([X|Y], Z):-
permutar(Y,L),
insertar(X,L,Z).
insertar(E,L,[E|L]).
insertar(E, [X|Y], [X|Z]):-
insertar(E, Y, Z).
Run Code Online (Sandbox Code Playgroud) 我的代码接收十六进制的值列表,我必须将它们传递给二进制文件并将每个结果放在一个列表中,但我有这两个错误,我不知道如何解决它们
Pixels.hs:121:29:
Occurs check: cannot construct the infinite type:
t0 = Bool -> [a1] -> t0
In the return type of a call of `modA'
Probable cause: `modA' is applied to too many arguments
In the expression:
modA (o ++ [(k `mod` 2)]) (l + 1) (k `div` 2) otherwise o
In an equation for `modA':
modA o l k
| l < 8 = modA (o ++ [(k `mod` 2)]) (l + 1) (k `div` 2) otherwise o
Pixels.hs:126:89: …Run Code Online (Sandbox Code Playgroud)