Got it! Thanks a ton for the help joel, turned out to be a pretty easy solution after you figure it out, but isnt everything!
rotate(List, R):- rotate(List, R1, H), R = [H|R1].
rotate([H], [], H).
rotate([H|T], L, R) :- rotate(T, T1, R), L = [H|T1].
hmm, i tried to do what you've said but i havent been able to get what i want. Here is what i got so far, it will return the last element of the list, and also the list without the last element:
rotate([H], [], H).
rotate([H|T], [H|T1], R) :- rotate(T, T1, R).
example query:
rotate([1,2,3]...
Hello all. I am pretty new to prolog and understanding it so-so thus far. I have question, which seems simple, but i have not been able to come up with a solution. Its as follows:
Given a list, rotate it to the right. An example query is rotate([1,2,3], R). => R=[3,1,2]; false. There is also...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.