Group Abstract Group Abstract

Message Boards Message Boards

Generating a special m x n matrix?

Posted 10 years ago
POSTED BY: Ulrich Utiger
5 Replies

The number of elements 'm' can be given by:

Pochhammer[n, r]/r!

Check:

Table[Length[GiveList[n, r]], {n, 1, 7}, {r, 1, 7}] // Grid
Table[Pochhammer[n, r]/r!, {n, 1, 7}, {r, 1, 7}] // Grid
POSTED BY: Sander Huisman
Posted 10 years ago

@Sander: Wow, this works. Thanks a lot. I was trying something with an integer c incrementing it and transforming it into base r with IntegerDigits. Far too complicate...

@Bill: You have almost done it too. Thank you anyway. Maybe I can complete it and test it for speed against the method of Sander as I will use the function in a loop for big n and r.

POSTED BY: Ulrich Utiger

The problem with my two other solutions is that you start off with a very large list and sieve a lot of them out. For n and r below 6 or so this is fine, however if you try 10 or so it will not work as you start off with a list of 10^10 elements and filter it, will never work; too big.

IntegerDigits works similarly but you will also start off with way too many, and you filter more and more for higher r and n....

POSTED BY: Sander Huisman
Posted 10 years ago

.

f[n_, r_] := Select[IntegerDigits[Range[0, 2^n-1], r, n]+1, LessEqual @@ # &]

In[2]:= f[2, 2]

Out[2]= {{1, 1}, {1, 2}, {2, 2}}

In[3]:= f[3, 2]

Out[3]= {{1, 1, 1}, {1, 1, 2}, {1, 2, 2}, {2, 2, 2}}

I am not certain that I have interpreted your 'r' correctly.

POSTED BY: Bill Simpson
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard