Comment detail

分数を小数に展開 (Nested Flatten)
他のハッシュ使ったのと同じアルゴリズムです。効率を保ったまま独自性が出せないので、悔しい。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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).

Index

Feed

Other

Link

Pathtraq

loading...