Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mac Mac is offline
external usenet poster
 
Posts: 213
Default Column Combinatorics

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.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Column Combinatorics

Mac,

So you want to have every combination of 11 ones in 20 cells, well it's a
lot. Put the numbers 1 to 20 in A1 - A20

Right click the worksheet tab, view code and paste this in and run it.
Depending on your PC you may have time to make a coffee.

What it will do is produce a list of number the first of which are the
numbers 1 to 11 indicating that is your first combination a 1 in each of
those cells. The last combination are the numbers 10 to 20 which is your last
set of cells to put a number 1 in. Altogether there are 167960 combinations
so happy typing

Sub combinations56()
'Perm any 11 from 20
'Numbers 1 to 20 in Column A 1 - 20
col = 2
last = Cells(Rows.Count, "A").End(xlUp).Row
For a = 1 To last - 10
For b = a + 1 To last - 9
For c = b + 1 To last - 8
For d = c + 1 To last - 7
For e = d + 1 To last - 6
For f = e + 1 To last - 5
For g = f + 1 To last - 4
For h = g + 1 To last - 3
For i = h + 1 To last - 2
For j = i + 1 To last - 1
For k = j + 1 To last

Cells(L + 1, col) = Cells(a, 1) & ", " & Cells(b, 1) & ", "
& Cells(c, 1) & ", " & Cells(d, 1) _
& ", " & Cells(e, 1) & ", " & Cells(f, 1) & ", " & Cells(g,
1) & ", " & Cells(h, 1) & ", " & Cells(i, 1) & ", " & Cells(j, 1) & ", " &
Cells(k, 1)

If L < 65535 Then
L = L + 1
Else
L = 0
col = col + 1
End If
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
End Sub


Mike


"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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
divide column(x) by column(y) to give column(x/y) in excel? James New Users to Excel 2 April 24th 23 11:46 AM
Referencing date column A & time column B to get info from column TVGuy29 Excel Discussion (Misc queries) 1 January 24th 08 09:50 PM
Return text in Column A if Column B and Column K match jeannie v Excel Worksheet Functions 4 December 13th 07 07:36 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
what formula do i put for column m = column k minus column l in e. jenniss Excel Discussion (Misc queries) 5 January 6th 05 08:18 PM


All times are GMT +1. The time now is 04:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"