prolog - Create predicates given the last n elements of a list -


example:

?-lastn([1,2,3,4],3,t). t = [2,3,4] 

this whay i'm write:

lastn(l,n,r):- length(l,x), x1 x-n, lastt(l, n,r). lastt(l,0,l). lastt(x,[h|t],l):- x2 x-1, lastt(t,x2,l). 

i assume question 'predicate last n elements in list' , meant do. it's simple discarding of first element after counting how many elements have discarded, right? not deal improper input @

lastn(l,n,r):- length(l,x), x1 x-n, lastt(l,x1,r). lastt(l,0,l). lastt([h|t],x,l):- x2 x-1, lastt(t,x2,l). 

Comments

Popular posts from this blog

javascript - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned -

amazon web services - When using Cognito credentials with AWS in a browser (javascript), keep getting "missing credentials" error -

c# - How to set the datatextfield value instead of the value on a drop down list? -