On Fri, Jul 31 2015, Christopher Fisher <[email protected]> wrote:

Thank you Tamas. I added return a and restructured the code (I think some formatting was lost when pasting). Based on the examples I tested, it appears to work. Can you recommend an efficient method of inputing an array of numbers. For example:

a = [10,12]

p = perm_matrix(a,2)

p = [10 10; 10 12; 12 10; 12 12]

I could probably hack something together that maps elements of a to the elements of p (0 through n-1), but you might have a more efficient and elegant solution.

A trivial modification takes care of that, see
https://gist.github.com/tpapp/43131b48f1afd97f1018

Regarding the second question, the combinations function (I believe this is what you were referring to) would treat (1,2) and (2,1) as indistinguishable. For example, the code below yields only three unordered pairs rather than six ordered pairs

Just use permutations --- see example in the gist above.

Best,

Tamas

Reply via email to