[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# determine all possible combinations of string

Posted on 2010-01-04
Medium Priority
456 Views
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?
0
Question by:Fairfield
• 4
• 2
• 2
• +1

LVL 75

Expert Comment

ID: 26175848
The count, or the actual values?
0

Author Comment

ID: 26175853
Well, if I can get the actual values, that would be great.
0

LVL 27

Expert Comment

ID: 26175890
Well the count of possible values would be: 36^9 = 101,559,956,668,416.
0

LVL 75

Expert Comment

ID: 26175901
Yeah. And I don't think EE will let us post that long of a string ;)
0

Author Comment

ID: 26175906
Does someone have some code that would generate this in a file?
0

LVL 27

Expert Comment

ID: 26175912
Do you really want to generate them or be able to search for that pattern or what?
0

LVL 75

Expert Comment

ID: 26175913
Actually, it would be even larger if you are going case-insensitive and allowing upper- and lower-case.
0

LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 26176130
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
``````
0

LVL 28

Expert Comment

ID: 26178624
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;
}
}
``````
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
###### Suggested Courses
Course of the Month18 days, 17 hours left to enroll