manghel

28 Reputation

4 Badges

14 years, 296 days

MaplePrimes Activity


These are replies submitted by manghel

Thanks!! Your comments and suggestions helped indeed. Just a few remarks. Using just "permute" doesn't quite do the job, since it does a permutation, which is not exactly what I want. In a permutation we miss these pairs: [0,0],[1,1],[2,2]. See below l := [0, 1, 2]; with(combinat, cartprod); combinat[permute](l, 2); [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]] A way around might be to redefine the list by doubling each element. This way, we do not miss the pairs listed above: l := [0, 0, 1, 1, 2, 2]; combinat[permute](l, 2); [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]] The right function seems to be "cartprod" in the same package. It returns a table, but it does what I wanted in the first place: l := [0, 1, 2]; t := cartprod([l, l]); while `not`(t[finished]) do t[nextvalue]() end do [0, 0] [0, 1] [0, 2] [1, 0] [1, 1] [1, 2] [2, 0] [2, 1] [2, 2]
Page 1 of 1