Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GCJ Watersheds

33 views
Skip to first unread message

neng...@gmail.com

unread,
Jun 5, 2015, 9:25:57 AM6/5/15
to
I just posted a program in Picat for the GCJ Watersheds problem. I am wondering how many lines a Prolog program would require.

https://groups.google.com/forum/#!topic/picat-lang/1QC3KWwfyA8

Cheers,
Neng-Fa

Jan Burse

unread,
Jun 8, 2015, 3:41:23 PM6/8/15
to
Some questions about Picat:

- You seem to use here and then foreach. How fast is
foreach in Picat? In many Prologs it is often provided
as part of a library, and there it is implemented via goal
copying. Does Picat also do goal copying?

- You pick the first element via sort().first(). Istn't this
a typical job for some aggregate functions. In Prologs
there is often an aggregate library, although sometimes
they also boil down to sort().first(), but not necessarely.
Does Picat also have an aggregate library?

Bye


neng...@gmail.com schrieb:

Joachim Schimpf

unread,
Jun 12, 2015, 1:19:13 PM6/12/15
to
On 05/06/15 14:25, neng...@gmail.com wrote:
> I just posted a program in Picat for the GCJ Watersheds problem.
> I am wondering how many lines a Prolog program would require.

An ECLiPSe program is very similar in length, without sacrificing
as many Prolog properties as Picat:


main :-
read_token(input, NProblems, integer),
( for(P,1,NProblems) do

read_token(input, N, integer),
read_token(input, M, integer),
dim(Alts, [N,M]),
( foreachelem(AltIJ,Alts) do
read_token(input, AltIJ, integer)
),

dim(Sinks, [N,M]),
( foreachindex([I,J],Alts), param(Alts,Sinks,N,M) do
( setof(t(Alt1,I1,J1), (
( I1=I, J1 is J-1, J1>=1
; I1=I, J1 is J+1, J1=<M
; J1=J, I1 is I-1, I1>=1
; J1=J, I1 is I+1, I1=<N
),
Alt1 is Alts[I1,J1],
Alt1 < Alts[I,J]
), [t(_Alt1,I1,J1)|_])
->
arg([I1,J1], Sinks, Sink),
arg([I,J], Sinks, Sink)
;
true
)
),
( foreachelem(Sink,Sinks), fromto(0'a,Id,Id1,_) do
( var(Sink) -> Sink=Id, Id1 is Id+1 ; Id1=Id )
),

printf("Case #%d:", [P]),
( foreachelem(Sink,Sinks,[_,J]) do
( J>1 -> put(0' ) ; nl ), put(Sink)
), nl
).


Cheers,
Joachim
0 new messages