![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Code Samples & Tips Share your recent discoveries and ideas with other users. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi,
I developed a sub for computinf the amout of combinations, given a population N, choose subset K (notation: choose(n,k). Example: how many combinations are possible for 7 cards from 52? choose(52,7). To compute n!/((n-k)!*k!) Because this creates an overflow for relatively small numbers I created an alternative and really fast routine. Code:
Sub Choose(nn,kk)
' effficient Choose method implementation
If (nn<0) OR (kk<0) Then Msgbox("Invalid negative parameter in Choose()..")
If (nn<kk) Then Return 0
If (nn=kk) Then Return 1
delta = 0
imax = 0
If (kk < (nn-kk)) Then 'choose(100,3)
delta = nn-kk
imax = kk
Else 'choose(100,97)
delta = kk
imax = nn-kk
End If
ans = delta+1
For i = 2 To imax
ans = (ans * (delta + i))/i
Next
Return ans
End Sub
Have fun Marc |
|
|||
|
Marc
Have you seen my answer to your previous thread regarding combinations ? It might help you... Combinations function
__________________
David Erez Ramat Hasharon, Israel |
|
|||
|
Hi David,
Yes I have and I find it very useful. Thank you for that, by the way... However I needed an application for my main application to find a next combination without using recursive programming. I found it at: http://msdn.microsoft.com/msdnmag/is...n/default.aspx I translated the code a bit and added some for my own code. Now I can use any combination and find its immediate successor or predecessor. Marc |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Choose Folder - Optimized Compilation | orhan | Questions & Help Needed | 9 | 05-15-2008 02:36 PM |
| Combinations application | Stellaferox | Share Your Creations | 0 | 02-21-2008 08:24 PM |
| Combinations function | derez | Share Your Creations | 0 | 02-04-2008 11:40 AM |
| code to write out combinations e.g. (10 choose 3) | Stellaferox | Questions & Help Needed | 4 | 02-04-2008 05:51 AM |
| List of possible combinations for x numbers. | EdQas | Questions & Help Needed | 3 | 10-07-2007 09:18 AM |