determine all possible combinations of string

I am trying to determine all of the possible combinations of all alpha-numerics with the following format xxxxxx-xxx where x can be any alpha numberic.  Can someone please help with this?
FairfieldAsked:
Who is Participating?
 
käµfm³d 👽Commented:
You put "Sql Server 2008" as your zone, so here is sql code. You would select the "Results to File" option to generate a file.

I'm not even sure how this will work out--meaning if the file will be too large to store, since it has already been stated how many possibilities this kind of operation will generate. I am not in a position to test if fully, so good luck :)

I only included upper-case characters and numbers. To include both lower- and upper-case, add another while loop with the following:

set @iterator = 97

while @iterator < 123
begin
      insert into #alphanum values (char(@iterator))
      set @iterator = @iterator + 1;
end

set nocount on
create table #alphanum  -- temporary table
(
	val char(1)
)

declare @iterator int

set @iterator = 48

while @iterator < 58
begin
	insert into #alphanum values (char(@iterator))
	set @iterator = @iterator + 1;
end

set @iterator = 65

while @iterator < 91
begin
	insert into #alphanum values (char(@iterator))
	set @iterator = @iterator + 1;
end

set nocount off
select a.val + b.val + c.val + d.val + e.val + f.val + '-' + g.val + h.val + i.val
from #alphanum as A
cross join #alphanum As B
cross join #alphanum As C
cross join #alphanum As D
cross join #alphanum As E
cross join #alphanum As F
cross join #alphanum As G
cross join #alphanum As H
cross join #alphanum As I

set nocount on
drop table #alphanum

Open in new window

0
 
käµfm³d 👽Commented:
The count, or the actual values?
0
 
FairfieldAuthor Commented:
Well, if I can get the actual values, that would be great.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Chris LuttrellSenior Database ArchitectCommented:
Well the count of possible values would be: 36^9 = 101,559,956,668,416.
0
 
käµfm³d 👽Commented:
Yeah. And I don't think EE will let us post that long of a string ;)
0
 
FairfieldAuthor Commented:
Does someone have some code that would generate this in a file?
0
 
Chris LuttrellSenior Database ArchitectCommented:
Do you really want to generate them or be able to search for that pattern or what?
0
 
käµfm³d 👽Commented:
Actually, it would be even larger if you are going case-insensitive and allowing upper- and lower-case.
0
 
peakpeakCommented:
Here's another example:
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// next_permutation.cpp : Illustrates how to use the
//                        next_permutation function.
//
// Functions:
//
//    next_permutation : Change the order of the sequence to the
//                       next lexicograhic permutation.
//////////////////////////////////////////////////////////////////////

// disable warning C4786: symbol greater than 255 character,
// okay to ignore
#pragma warning(disable: 4786)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <search.h>

using namespace std ;

// Define a template class vector of strings
typedef vector<string> StrVector ;

//Define an iterator for template class vector of strings
typedef StrVector::iterator StrVectorIt ;

//Define an ostream iterator for strings
typedef ostream_iterator<string> StrOstreamIt;

void Permutate(char *pattern);
//int compare((const void *) arg1, (void *)arg2));

void main()
{
	Permutate("ABC"); // Replace with your pattern
}

void Permutate(char *pattern)
{
	int len = strlen(pattern);
    StrVector Pattern(len) ;
    StrVectorIt start, end, it ;
    StrOstreamIt outIt(cout, " ") ;
	
	start = Pattern.begin() ;   // location of first element of Pattern
    end = Pattern.end() ;       // one past the location last element of Pattern

    // Initialize vector Pattern
	for (int i = 0; i < len; i++)
		Pattern[i] = pattern[i];

    // print content of Pattern
    cout << "Before calling next_permutation...\n" << "Pattern: " ;
    for(it = start; it != end; it++)
        cout << *it << " " ;
    cout << "\n\n" ;

    // Generate all possible permutations

    cout << "After calling next_permutation...." << endl ;
    while (next_permutation(start, end))
    {
        copy(start, end, outIt);
        cout << endl;
    }
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.