inverse matrix by mskzzzz

t.
f:-1>2.
b(N,V):-between(0,N,V).
a(A):-assert(A).
r(A):-retract(A).
d(I,W):-J is I,r(m(J,V)),Z is V rdiv W,a(m(J,Z)).
s(I,V):-J is I,r(m(J,_)),a(m(J,V)).
n(I,V):-J is I,m(J,V).
o(K,T):-b(8,I),\+d(K*9+I,T);t.
i(K,J,T,U):-b(8,I),(I=K->(Q is -U rdiv T,s(J*9+I,Q));(n(J*9+I,X),n(K*9+I,Y),Z is X-Y*U,s(J*9+I,Z))),f.
j(K,T):-b(8,J),(J=K->t;n(J*9+K,U),i(K,J,T,U)),f.
v:-n(0,V),(V<19->S=0;S=3),(b(8,Z),K is(Z+S)mod 9,(n(K*9+K,T),o(K,T),T1 is 1 rdiv T,s(K*9+K,T1),j(K,T)),f;p).
p:-b(8,I),(b(8,J),K is I*9+J,m(K,V),format('~d',[V]),(J<8->tab(1));nl),f;!.
x(L):-b(80,I),nth0(I,L,V),\+a(m(I,V));v.
g(F,L,I):-I<1->x(L);read_line_to_codes(F,C),atom_codes(A,C),concat_atom(Z,' ',A),maplist(atom_number,Z,Y),append(L,Y,M),g(F,M,I-1).
m:-open('/dev/fd/0',read,F),g(F,[],9).

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page