RosettaCodeData/Task/Time-a-function/Picat/time-a-function.picat

30 lines
650 B
Plaintext

import cp.
go =>
println("time/1 for 201 queens:"),
time2(once(queens(201,_Q))),
nl,
% time1b/1 is a used defined function (using statistics/2)
Time = time1b($once(queens(28,Q2))),
println(Q2),
printf("28-queens took %dms\n", Time),
nl.
% N-queens problem.
% N: number of queens to place
% Q: the solution
queens(N, Q) =>
Q=new_list(N),
Q :: 1..N,
all_different(Q),
all_different([$Q[I]-I : I in 1..N]),
all_different([$Q[I]+I : I in 1..N]),
solve([ffd,split],Q).
% time1b/1 is a function that returns the time (ms)
time1b(Goal) = T =>
statistics(runtime, _),
call(Goal),
statistics(runtime, [_,T]).