Generating a list in prolog -


Hello, I want to create a program in Prol, which is given a list of numbers and a number, all of these consoles Number position in the second list.

For example list (5104,5,6,5) and number = 5 should be new list

  (1,4,6)  

Here my code is so far

  position (x, [x | _], 1). Position (X, [P | T], N): - Position (X, T, N1), NN + 1 is Find (X, [H], Z): - Post (X, [H | T], n), enclosed ([], n, z).  

Returns the first consent of X in the list of posts, but I do not know how to move forward Can you help me?

If this is not an assignment, you can benefit from using build-build Findall / 3 and nth1 / 3:

 ? - Search (Anth, NT1 (nand, [5, 10, 4, 5, 5, 5, 5, NFS]) Nths = [1, 4, 6] taking only nth1 phrases, and this is going on, you You can see that it is on the back side and looking for many solutions, we use only the search to collect them in a list.  
 ? - nth1 (nth, [ 5,10,4,5,6,5], 5) .nth = 1; anith = 4; nth = 6.  

nth1 / 3, when a variable for the first parameter Using, give me a list list where the second parameter is in the list of second parameters Is.


Comments