div0(A,B,R,M):-R is A // B, M is A mod B.
div(A,B,R):-empty_assoc(C),div(A,B,C,D,D,R).
div(0,_,_,Dr,[],Dr).
div(A,_,C,Dh,['}'],Dr):-get_assoc(A,C,Val),match0(Dh,Val,Dr),!.
div(A,B,C,Dh,[R|Dt],Dr):-A1 is A * 10, div0(A1,B,R,M), put_assoc(A,C,[R|Dt],C1), div(M,B,C1,Dh,Dt,Dr).
match0(D,V,R):-length(D,LenD),length(V,LenV),Len is LenD - LenV, t(Len,D,V,R).
t(0,_,V,['{'| V]).
t(N,[D|Ds],V,[D|Rs]):-succ(N1,N),t(N1,Ds,V,Rs).
:- div(3,14,X0),concat_atom(['0.'|X0],X),writeln(X).
katsu
#1318()
[
Prolog
]
Rating0/0=0.00
div0(A,B,R,M):-R is A // B, M is A mod B. div(A,B,R):-empty_assoc(C),div(A,B,C,D,D,R). div(0,_,_,Dr,[],Dr). div(A,_,C,Dh,['}'],Dr):-get_assoc(A,C,Val),match0(Dh,Val,Dr),!. div(A,B,C,Dh,[R|Dt],Dr):-A1 is A * 10, div0(A1,B,R,M), put_assoc(A,C,[R|Dt],C1), div(M,B,C1,Dh,Dt,Dr). match0(D,V,R):-length(D,LenD),length(V,LenV),Len is LenD - LenV, t(Len,D,V,R). t(0,_,V,['{'| V]). t(N,[D|Ds],V,[D|Rs]):-succ(N1,N),t(N1,Ds,V,Rs). :- div(3,14,X0),concat_atom(['0.'|X0],X),writeln(X).Rating0/0=0.00-0+
[ reply ]