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

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -