My problem is:
Write a PROLOG program that, given two lists of integers INDEXS and VALUES, returns a list whose first element is the value stored in the position corresponding to the first element of INDEXS of the list VALUES. For example, given INDXS=[2,1,4,3] and VALUES=[2,4,6,8], the output is [4,2,8,6].
So far I have done the following:
newlist([], [], void).
newlist([void|Tail], Values, X) :- newlist(Tail, Values, X).
newlist([H|T], Values, X) :-
nth1(H, Values, Curr), %%Get element nr H in Values and bind it to Curr
add(Curr, X, [Curr|X]), %%Add Current to array X
newlist(T, Values, X). %%Recursive send back Tail, the values and new array X
And query the following:
newlist([2,1], [2,3], X).
If my prolog code is ok, I want to show my new list in the variable X. How can I do this? (I have already tried to print it.