I was working on the following problem:
The Cartesian Product of two sets is the set containing all the tuples produced from one element of one set and second element from the other set. Consider the sets A = {a, b, c} and B = {1, 2, 3}
The cartesian product of A and B = A ? B
= { (a,1), (a,2), (a,3), (b,1), (b,2), (b,3), (c,1), (c,2), (c,3) }
Write a Prolog program in which it is possible to issue goals to display all the tuples produced from the Cartesian Product of any two sets, including the empty set.
e.g. cartesian_product ([a,b,c],[1,2,3]) would display:
a 1 a 2 a 3
b 1 b 2 b 3
c 1 c 2 c 3
How can you do it using Prolog?
Shaun Tabone
The Cartesian Product of two sets is the set containing all the tuples produced from one element of one set and second element from the other set. Consider the sets A = {a, b, c} and B = {1, 2, 3}
The cartesian product of A and B = A ? B
= { (a,1), (a,2), (a,3), (b,1), (b,2), (b,3), (c,1), (c,2), (c,3) }
Write a Prolog program in which it is possible to issue goals to display all the tuples produced from the Cartesian Product of any two sets, including the empty set.
e.g. cartesian_product ([a,b,c],[1,2,3]) would display:
a 1 a 2 a 3
b 1 b 2 b 3
c 1 c 2 c 3
How can you do it using Prolog?
Shaun Tabone