I wrote a simple program to try and populate a list of a given length with elements that meet a certain constraint.
For example, I want to create a list of 4 integers between 0 and 9, which at least contains 3 and 4. I can think of several (thousands, really) such lists:
[3,4,0,0]
[0,3,4,0]
[3,1,9,4]
etc...
But SWI Prolog just returns false. Am I just making some kind of logical mistake, or am I using Prolog wrong?
My code:
is_single_digit_integer(N) :-
integer(N),
between(0, 9, N).
filled_list(Given, FillConstraint, OutLen, Out) :-
is_list(Out),
length(Out, OutLen),
length(Given, GivenLen),
between(0, OutLen, GivenLen),
maplist(FillConstraint, Out),
subset(Given, Out).
And running the example I described:
?- filled_list([3,4], is_single_digit_integer, 4, X).