Results 1 to 6 of 6

Thread: CALCULATE ALL COMBINATIONS? Brain Dead

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    1

    Question CALCULATE ALL COMBINATIONS? Brain Dead

    I've been racking my brain for the past several days trying to write a routine to calculate and show all posible combinations that can be made form a variable set of numbers

    ie; 123 gives you 6 possible combos and 4 gives you 24

    A basic buble or shell sor gets me partially there, but I'm missing the repitition of all combinations the can be made from each of the numbers in the set

    123
    132
    231
    213
    312
    321

    Does someone have the answer. I'm now Brain dead!

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Permutations maybe?

    First, a bit of terminology. You are talking about Permutations, not Combinations.

    Second, I have a description of the best algorithm and a VB application to generate all permutations of N objects. It is on my older computer. I will post some further information next time I fire up that system. BTW: The algorithm does not cope with duplicates. The VB application will generate permutations one at a time for each push of a command button for large N. For small N it will generate all permutations that fit in memory. It could be enhanced to store lots more in a Disk file.

    Third, just in case you have not thought deeply about this, for large N (say 15 or more), there are more permutations that you want to know about.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    The number of permutations for a sequence of length N is N! (N factorial). So for 15 that would be 1307674368000 permutations, which is a lot as Guv said.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    In case you don't want it to generate all those 1307674368000 permutations to fill your HDD, you can find a generator i made to generate any permutation by index. Should be here somewhere.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    What do you need the code for?

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Use fixed strings.

    Michael Simone: Brute force methods seem suitable for what you are doing. No need to use arrays, loops, subroutines, functions, or anything fancy. For permutations of more than 3-4 items, the fancy techniques start getting useful. Nobody wants to write thousands of lines of code, but why not write 10-20?

    I hope there are no syntax errors or typo's in the following. When not being paid, I am not as obsessive compulsive as usual.

    You need to generate all permutations of 3 items, which can never be more than two digits (or characters) each, allowing the use of 6-character strings and 2-character strings.

    Pad the single digit numbers with a leading space or a leading zero, whichever you prefer. Then you can work with fixed length strings. You can use the Mid Function & the Mid Statement to create permutations. Code something like the following should work.
    Code:
    Dim Permutation As String*6
    Dim MovingItem As String*2
    Dim TempString as String*2
    
    ‘Some code needed here to create the first Permutation.
    
    MovingItem = Left(Permutation, 2 )
    
    Mid(Permutation, 1, 2) = Mid(permutation, 3, 2) 
    Mid(Permuation, 3, 2) = MovingItem ‘This is the second Permutation
    
    Mid(Permutation, 3, 2) = Mid(Permutation, 5, 2)
    Mid(Permutation, 5, 2) = MovingItem ‘This is the third Permutation.
    
    TempString = Left(Permutation, 1, 2) ‘Full exchange required to swap first two items.
    Mid(Permutation, 1, 2) = Mid(Permutation, 3, 2)
    Mid(Permutation, 3, 2) = TempString ‘This is the fourth Permutation.
    Now use Half exchanges to create the last two permutations.

    If you are merely having fun with bets on horses, I hope you enjoy yourself. If you are trying to show a profit, you have a lot of work to do.

    Dutching a hand book is not a formidable task, but beating a parimutuel system is likely to be impossible.

    There are strategies based on probability estimates (rather than attempting to pick winners) which might be effective versus a parimutuel system, but beating a 17% to 22% take seems almost impossible. Note that the breakage tends to cause a 15% take to be an effective 17%, unless there is a negative pool. Races with negative pools tend to require special techniques and should probably be avoided.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width