psk09-cycle.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:08.0
disk size 774 Bytes
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
% The First 10 Prolog programming Contests

%query: cycle(i,i,o).
cycle(Dividend,Divisor,Repetition) :-
   Remainder is Dividend mod Divisor,
   RemQuotList = [],
   divide(Remainder,Divisor,RemQuotList,Repetition).

divide(Remainder,_,RemQuotList,Repetition) :-
   find_repetition(RemQuotList,Remainder,[],Repetition),
   !.
divide(Remainder,Divisor,RemQuotList,Repetition) :-
   Remainder10 is 10 * Remainder,
   Quot is Remainder10 // Divisor,
   NewRemainder is Remainder10 - Divisor*Quot,
   divide(NewRemainder,Divisor,[Remainder*Quot|RemQuotList],Repetition).

find_repetition([X*Quot|RemQuotList],Remainder,In,Out) :-
   ( Remainder == X ->
           Out = [Quot|In]
   ;
           find_repetition(RemQuotList,Remainder,[Quot|In],Out)
   ).
popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark