Trying to write something like generate(L, N) that will generate a list L of size N where each element is either a 0 or a 1. This is what I have but it doesn't work, any suggestions?
generate(L, 0) :- !.
generate(L, N) :- A is N - 1, B is random(2), generate([B|L], A).
I also tried something...
I'm trying to solve a problem using difference lists (which I don't really understand well and 2 weeks worth of reading on the net hasn't changed that). Basically I want to determine the depth of the elements in a list, ie, if I were to ask
depth([a,b,[c,[],[d,e]],f], L)
Prolog would answer
L...
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.