A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"possible number combinations" of different numbers of integers -.



 
 
Thread Tools Display Modes
  #1  
Old August 31st, 2004, 05:55 PM
rsdauer
external usenet poster
 
Posts: n/a
Default "possible number combinations" of different numbers of integers -.

what would the formula be to "see" all "possible number combinations" of any
given about of intigers (0-9)
  #2  
Old August 31st, 2004, 06:08 PM
sulprobil
external usenet poster
 
Posts: n/a
Default

Depends what you define as "combination" but anyway - your
solution should be found he
http://www-cs-faculty.stanford.edu/~knuth/news.html

HTH
sulprobil
  #3  
Old August 31st, 2004, 07:04 PM
Myrna Larson
external usenet poster
 
Posts: n/a
Default

Assuming you mean that you have 9 digits, and you want to know how many
different numbers can be constructed by rearranging these digits, you want the
number of permutations of 9 things taken 9 at a time. There are 362,880 such
permutations. Are you sure you want to see all of them?

There's no formula for this. It can be done with VBA.

I posted the following message, with the code, on July 25, 2000.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The routine is generic, i.e. it isn't written specifically
for a given population and set size.... It will do permutations or
combinations. It uses a recursive routine to generate the subsets, one routine
for combinations, a different one for permutations.

To use it, you put the letter C or P (for combinations or permutations) in a
cell. The cell below that contains the number of items in a subset. The cells
below are a list of the items that make up the population. They could be
numbers, letters and symbols, or words, etc.

You select the top cell, or the entire range and run the sub. The subsets are
written to a new sheet in the workbook.

Option Explicit

Dim vAllItems As Variant
Dim Buffer() As String
Dim BufferPtr As Long
Dim Results As Worksheet

Sub ListPermutations()
Dim Rng As Range
Dim PopSize As Integer
Dim SetSize As Integer
Dim Which As String
Dim N As Double
Const BufferSize As Long = 4096

Set Rng = Selection.Columns(1).Cells
If Rng.Cells.Count = 1 Then
Set Rng = Range(Rng, Rng.End(xlDown))
End If

PopSize = Rng.Cells.Count - 2
If PopSize 2 Then GoTo DataError

SetSize = Rng.Cells(2).Value
If SetSize PopSize Then GoTo DataError

Which = UCase$(Rng.Cells(1).Value)
Select Case Which
Case "C"
N = Application.WorksheetFunction.Combin(PopSize, SetSize)
Case "P"
N = Application.WorksheetFunction.Permut(PopSize, SetSize)
Case Else
GoTo DataError
End Select
If N Cells.Count Then GoTo DataError

Application.ScreenUpdating = False

Set Results = Worksheets.Add

vAllItems = Rng.Offset(2, 0).Resize(PopSize).Value
ReDim Buffer(1 To BufferSize) As String
BufferPtr = 0

If Which = "C" Then
AddCombination PopSize, SetSize
Else
AddPermutation PopSize, SetSize
End If
vAllItems = 0

Application.ScreenUpdating = True
Exit Sub

DataError:
If N = 0 Then
Which = "Enter your data in a vertical range of at least 4 cells. " _
& String$(2, 10) _
& "Top cell must contain the letter C or P, 2nd cell is the number " _
& "of items in a subset, the cells below are the values from which " _
& "the subset is to be chosen."

Else
Which = "This requires " & Format$(N, "#,##0") & _
" cells, more than are available on the worksheet!"
End If
MsgBox Which, vbOKOnly, "DATA ERROR"
Exit Sub
End Sub

Private Sub AddPermutation(Optional PopSize As Integer = 0, _
Optional SetSize As Integer = 0, _
Optional NextMember As Integer = 0)

Static iPopSize As Integer
Static iSetSize As Integer
Static SetMembers() As Integer
Static Used() As Integer
Dim i As Integer

If PopSize 0 Then
iPopSize = PopSize
iSetSize = SetSize
ReDim SetMembers(1 To iSetSize) As Integer
ReDim Used(1 To iPopSize) As Integer
NextMember = 1
End If

For i = 1 To iPopSize
If Used(i) = 0 Then
SetMembers(NextMember) = i
If NextMember iSetSize Then
Used(i) = True
AddPermutation , , NextMember + 1
Used(i) = False
Else
SavePermutation SetMembers()
End If
End If
Next i

If NextMember = 1 Then
SavePermutation SetMembers(), True
Erase SetMembers
Erase Used
End If

End Sub 'AddPermutation

Private Sub AddCombination(Optional PopSize As Integer = 0, _
Optional SetSize As Integer = 0, _
Optional NextMember As Integer = 0, _
Optional NextItem As Integer = 0)

Static iPopSize As Integer
Static iSetSize As Integer
Static SetMembers() As Integer
Dim i As Integer

If PopSize 0 Then
iPopSize = PopSize
iSetSize = SetSize
ReDim SetMembers(1 To iSetSize) As Integer
NextMember = 1
NextItem = 1
End If

For i = NextItem To iPopSize
SetMembers(NextMember) = i
If NextMember iSetSize Then
AddCombination , , NextMember + 1, i + 1
Else
SavePermutation SetMembers()
End If
Next i

If NextMember = 1 Then
SavePermutation SetMembers(), True
Erase SetMembers
End If

End Sub 'AddCombination

Private Sub SavePermutation(ItemsChosen() As Integer, _
Optional FlushBuffer As Boolean = False)

Dim i As Integer, sValue As String
Static RowNum As Long, ColNum As Long

If RowNum = 0 Then RowNum = 1
If ColNum = 0 Then ColNum = 1

If FlushBuffer = True Or BufferPtr = UBound(Buffer()) Then
If BufferPtr 0 Then
If (RowNum + BufferPtr - 1) Rows.Count Then
RowNum = 1
ColNum = ColNum + 1
If ColNum 256 Then Exit Sub
End If

Results.Cells(RowNum, ColNum).Resize(BufferPtr, 1).Value _
= Application.WorksheetFunction.Transpose(Buffer())
RowNum = RowNum + BufferPtr
End If

BufferPtr = 0
If FlushBuffer = True Then
Erase Buffer
RowNum = 0
ColNum = 0
Exit Sub
Else
ReDim Buffer(1 To UBound(Buffer))
End If

End If

'construct the next set
For i = 1 To UBound(ItemsChosen)
sValue = sValue & ", " & vAllItems(ItemsChosen(i), 1)
Next i

'and save it in the buffer
BufferPtr = BufferPtr + 1
Buffer(BufferPtr) = Mid$(sValue, 3)
End Sub 'SavePermutation


--------------------------------------------------------------------------------


On Tue, 31 Aug 2004 09:55:05 -0700, "rsdauer"
wrote:

what would the formula be to "see" all "possible number combinations" of any
given about of intigers (0-9)


  #4  
Old August 31st, 2004, 07:15 PM
Myrna Larson
external usenet poster
 
Posts: n/a
Default

Hi, sulprobil:

I wonder if most folks have the right tools to work with Knuth's files.

I followed your link to his site. The links on the page are to GZ files (some
kind of archive/zip file that I don't recognize), but luckily I have a program
that can open GZ files. Once I got that far, I found the archive content to be
a Post Script file. Since I have Adobe Acrobat, full version, I was able to
convert that to a PDF file.


On Tue, 31 Aug 2004 10:08:39 -0700, "sulprobil"
wrote:

Depends what you define as "combination" but anyway - your
solution should be found he
http://www-cs-faculty.stanford.edu/~knuth/news.html

HTH
sulprobil


  #5  
Old August 31st, 2004, 07:18 PM
Myrna Larson
external usenet poster
 
Posts: n/a
Default

On further exploration, I found Knuth's page has a link to an unzipper,
GZIP.EXE, and another to GhostScript, which can be used to view the PS file.


On Tue, 31 Aug 2004 10:08:39 -0700, "sulprobil"
wrote:

Depends what you define as "combination" but anyway - your
solution should be found he
http://www-cs-faculty.stanford.edu/~knuth/news.html

HTH
sulprobil


  #6  
Old September 1st, 2004, 12:58 AM
hgrove
external usenet poster
 
Posts: n/a
Default

Myrna Larson wrote...
I wonder if most folks have the right tools to work with Knuth's
files.

I followed your link to his site. The links on the page are to GZ
files (some kind of archive/zip file that I don't recognize), . . .


gzipped - standard archive format on all Unix/Linux/BSD systems, and
incorporated into nearly all Windows archiving programs written from
2000 on.

but luckily I have a program that can open GZ files. Once I got
that far, I found the archive content to be a Post Script file.
Since I have Adobe Acrobat, full version, I was able to convert
that to a PDF file.


You've already mentioned GhostScript as an alternative way to view PS
files (or convert them to PDF, HTML or plain text). There's also a
shareware PS viewer named RoPS and an open source viewer/converter
named MakePDF (still in beta).


---
Message posted from http://www.ExcelForum.com/

  #7  
Old September 1st, 2004, 04:17 AM
Myrna Larson
external usenet poster
 
Posts: n/a
Default

Hi, Harlan:

Since I've never used a Unix/Linus/BSD system (or a Mac), their file formats
are all Greek to me.

FWIW, WinZip v8 *can* handle the GZ format (as well as PowerDesk, the program
I normally use).

Thanks for the additional info on viewing PS files. I checked out RoPS. It
works OK, but the down side (for me, considering the use I would get from it)
is the cost: $45. I guess I'll stick to converting to PDF, since I have the
full version of Acrobat 6.

Myrna Larson


On Tue, 31 Aug 2004 18:58:35 -0500, hgrove
wrote:

Myrna Larson wrote...
I wonder if most folks have the right tools to work with Knuth's
files.

I followed your link to his site. The links on the page are to GZ
files (some kind of archive/zip file that I don't recognize), . . .


gzipped - standard archive format on all Unix/Linux/BSD systems, and
incorporated into nearly all Windows archiving programs written from
2000 on.

but luckily I have a program that can open GZ files. Once I got
that far, I found the archive content to be a Post Script file.
Since I have Adobe Acrobat, full version, I was able to convert
that to a PDF file.


You've already mentioned GhostScript as an alternative way to view PS
files (or convert them to PDF, HTML or plain text). There's also a
shareware PS viewer named RoPS and an open source viewer/converter
named MakePDF (still in beta).


---
Message posted from http://www.ExcelForum.com/


  #8  
Old September 2nd, 2004, 07:28 AM
Harlan Grove
external usenet poster
 
Posts: n/a
Default

"Myrna Larson" wrote...
Since I've never used a Unix/Linus/BSD system (or a Mac), their file
formats are all Greek to me.


But you have a thorough understanding of .zip file layout?

File formats are common across OS's using the same character set (i.e.,
files do differ EBCDIC vs ASCII, but don't differ much among ASCII-based
OS's).

FWIW, WinZip v8 *can* handle the GZ format (as well as PowerDesk, the
program I normally use).


As can PowerArchiver, which I normally use. These days I'd guess everything
other than perhaps PkZip can support all compressed archive formats that
have ever been. FWLIW, there's also bzip (.bz) format, which can usually
attain greater compression that .zip or .gz. PowerArchiver supports it.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Phone number formatting Jean971 Contacts 3 July 1st, 2004 10:35 PM
Adding zero's to the beginning of a number kukarooza General Discussion 5 June 28th, 2004 07:39 PM
Enter Numbers as Text in Social Security Number Format Frank Kabel Worksheet Functions 0 March 18th, 2004 09:17 PM
Count incidences of part numbers jmdaniel Worksheet Functions 13 March 9th, 2004 05:46 PM


All times are GMT +1. The time now is 06:42 PM.


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