I'v tried a few features to implement a predicate which finds all the combinations, like in that example:
List = [[1, 2], [1, 2, 3]]
These should be the output,
Comb = [[1,1],[1,2],[1,3],[2,1],[2,2],[2,3]]
but all the solutions I've found were using findall
which I don't want to use in my task.
How can I differently implement the predicate, avoiding findall
?
Or maybe how can I implement my_findall
without using any built-in features?
A solution like here, without built-in predicates would be great
Thanks to the helpers!
I'm not so sure this is the most efficient approach, but it's fairly transparent. The idea here is to define the problem in recursive (or inductive) "layers":
multiply_element/4
actually combines two rules into one: it defines multiplication of a list by a single element, and prepends those results as individual elements to a given list.A sample result:
Some quirks with the above implementation:
But it does illustrate how the problem can be solved without using
append/3
or other list-based pre-defined predicates.