|
28-12-2006, 22:42
|
|
|
חבר מתאריך: 24.11.06
הודעות: 5
|
|
שאלה ב PROLOG ..... :(
בשביל למנוע בלבולים של עברית/אנגלית, אני ירשום תשאלה רק באנגלית...
Create a predicate ascSeq(L,AS) that holds if L can be divided to a list of (strictly) ascending
sequences (each such sequence must be of length of at least 2), and this list of sequences is AS.
E.g: ascSeq([1,2,3,2,19,1,5],X) should output X = [[1, 2, 3], [2, 19], [1, 5]] but ascSeq([2,4,6,2],X)
should fail.
התחלתי לכתוב משו, אבל נתקעתי קצת....
%שרשור איבר לרשימה
append(X1,X,[X1|X]).
append(H1,[H2|L2],L3) :- append(H2,L2,[H1|L3]).
max(A,B,B) :- A < B.
max(A,B,A).
%מקבל: איבר, רשימה, אורך נוכחי של תת רשימה
ascSeq(L,AS) :- ascSeq(X,[],0,AS).
ascSeq([],)
ascSeq([],CL,_,AS) :- append(CL,AS .
islengthgood([X|L]) :- islengthgood(X,L).
islengthgood(X,[X1|L]) :- max(X,X1,MAX),
תודה.. אני ממש מיואשתתתתתתתתת
|
|