Hello everybody,
I am studing the book of Paul Wellin and I am trying to solve a problem. But I am stuck, This is the question
Using ReplaceList write a function 'cartesianproduct' that works with two lists givings
CartPr[{{x1,x2},{y1,y2}}] = {{x1,y1},{x1,ÿ2} ,{x2,y1} ...}
first tried directly and that works
In
ReplaceList[{{x1, x2, x3}, {y1, y2}}, {{___, a_, ___} , {___, b_, ___}} -> {{a, b}}]
Out[11]= {{{x1, y1}}, {{x1, y2}}, {{x2, y1}}, {{x2, y2}}, {{x3,
y1}}, {{x3, y2}}}
and now the function that doesn't work
cartesianProduct[{x_List, y_List}] =
ReplaceList[{x, y}, { , a, ___ } , { , b, ___ } -> {a, b}]
ReplaceList::innf: Non-negative integer or Infinity expected at position 3 in ReplaceList[{x,y},{,a,},{,b,}->{a,b}]. >>
What do I do wrong ?
Thanks