View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default Column Combinatorics

.. elaborating ..
'msgbox' probably isn't what you want, but you can
change that:

Const gN = 20, gK = 11

Sub Main()
Call Recurse(0, 1, "") ' level, start, string
End Sub

Sub Recurse(pLevel%, pStart%, pStr$)
Dim i1%
If pLevel = gK Then ' got gN items
MsgBox pStr
Exit Sub
End If
For i1 = pStart To gN + gK - pLevel - 1
Call Recurse(pLevel + 1, i1 + 1, pStr & i1 & " ")
Next i1
End Sub ' Dave D-C

Mac wrote:
Hi all,
instead of reenventing the wheel I turn to this group with my case:
assume a single column consisting of 20 cells; now, 11 cells contain the
number 1, others are empty. What I'm looking for is an elegant way of
elaborating all possible combinations of these 11 pieces as how they can be
scattered throughout 20 empty cells. Mind you, this could be done by hand
(ahhhhh), but a few combinations could be ommitted simply by mistake, and to
accomplish this would be a real drudgery; that's why I'm looking for an
algorithm to have this done for me. Any ideas?
Mac.



----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.pronews.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= - Total Privacy via Encryption =---