View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default Function for combinations

hi Robert,

this is an example to get started


Sub combin()
Dim nbchiff As Integer, nb As Integer, plage As Range, cel As Range, list
list = Array(15, 23, 26, 29, 40)
nbchiff = InputBox("nombre de chiffre ?")
For nb = 1 To nbchiff
Cells(nb, 1) = (0 + list(nb - 1))
Next
Cells(nbchiff, 1).Select
bi:
Set plage = Range(Cells(1, ActiveCell.Column), ActiveCell)
plage.Cells(1).Offset(0, 1).Select
For Each cel In plage
For nb = 1 To nbchiff
ActiveCell = cel & (",") & (1 + list(nb - 1))
ActiveCell.Offset(1, 0).Select
Next nb
Next cel
ActiveCell.Offset(-1, 0).Select
If ActiveCell.Column < nbchiff Then GoTo bi
End Sub



--
isabelle



Le 2012-01-19 22:11, Robert Crandal a écrit :
"GS" wrote in message ...

This smacks of Lottery Wheeling. My advice is to use an array for the combinations and use its index for the identifier.



For now, suppose that you do NOT have the full list of combos stored in
an array. Suppose I gave you the following 5-combination as input:

"15 23 26 29 40"

Can you think of a good algorithm or scheme for computing the index
number of this combination??? I'm looking for ways to assign unique
identifiers for ANY general combination that might involve N numbers
chosen K at a time. Does that make sense??

Thanks for your help again everyone.