Jump to content

combinations generator


Recommended Posts

hi, i want to list combinations but kinda not all possible combinations for example,

i have 11 sets and i need 11 digit combinations

{024}{597}{597}{024}{13}{024}{13}{597}{68}{597}{024}

ex:

05501015650 is a combination (The first digit of each set)
05501015652
05501015654
05501015690
...

total as i calculated should be around 52488 combinations.

but i cant wrap my head around how to code it, can any one help?

Link to comment
Share on other sites

Here to start you up :

Global $Line = 0

HotKeySet ("[ESC]","_Exit")

FileDelete ("Test.txt")

Local $Set[11][3] = [[0,2,4],[5,9,7],[5,9,7],[0,2,4],[1,3,""],[0,2,4],[1,3,""],[5,9,7],[6,8,""],[5,9,7],[0,2,4]]

Combi("", -1, Ubound($Set,1))

Func Combi($Str, $Ind, $MaxLen)
  if StringLen($Str) = $MaxLen Then
    $Line += 1
    FileWriteLine("Test.txt", "Line " & StringFormat("%05i", $Line) & " : Combination = " & $Str)
    Return
  EndIf
  $Ind += 1
  For $j = 0 to Ubound ($Set,2) - ($Set[$Ind][2]=""?2:1)
    Combi($Str & $Set[$Ind][$j], $Ind, $MaxLen)
  Next
EndFunc

Func _Exit ()
  Exit
EndFunc

Recursion is a nice thing, but it is not the fastest.  Maybe adding a progress bar.  And using file handle will greatly increase the speed...

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...