Hi Joachim, First one is slightly more efficient than the second in my case. Regards, Panagiotis On 29-Mar-23 11:20 AM, Joachim Schimpf via ECLiPSe-CLP-Users wrote: > On 27/03/2023 10:51, Marco Gavanelli wrote: >> >> Anyway, what about: >> >> L[0] = 1 >> >> forall i>0 >> L[i] <= maxlist(L[0..(i-1)]) + 1 >> ? >> >> I hope the intuition is clear, with L[0..(1-i)] I mean the sublist of >> the first i elements of the list L. > > > Here are two implementations, one of which may be faster in your > circumstances. > > % version using max(List) > precede1(Xs) :- > eval_to_array(Xs, Xz), > arity(Xz, N), > Xz #:: 1..N, > Xz[1] #= 1, > ( for(I,2,N), param(Xz) do > Xz[I] #=< max(Xz[1..I-1]) + 1 > ). > > % incremental version using max(Xi,Xj) > precede2(Xs) :- > eval_to_array(Xs, Xz), > arity(Xz, N), > Xz #:: 1..N, > ( foreacharg(X,Xz), fromto(0,Max1,Max2,_) do > X #=< Max1 + 1, > Max2 #= max(Max1,X) > ). > > > -- JoachimReceived on Wed Mar 29 2023 - 13:12:58 CEST
This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:21 CEST