ripper121:
Once you decide how many combinations you really need, you have two choices. A series of nested for loops that each count from 0-255, or count with a single number and extract each byte with bit-fiddling.
//
// FILE: perm1.pde
// AUTHOR: Rob Tillaart
// DATE: 2010-11-23
//
// PUPROSE: demo permutations
//
char permstring[12] = "123456789A";
void permutate(int n)
{
if (n==0) // end reached print the string
{
//for (int i = 0; i < strlen(permstring); i++)
// Serial.print(permstring[i]);
//Serial.println();
return;
}
for (int i = 0; i <n; i++)
{
// swap
char t = permstring[i];
permstring[i] = permstring[n-1];
permstring[n-1] = t;
// permutate substrings
permutate(n-1);
// swap back
t = permstring[i];
permstring[i] = permstring[n-1];
permstring[n-1] = t;
}
}
void setup()
{
Serial.begin(115200);
unsigned long time = millis();
permutate(strlen(permstring));
time = millis() - time;
Serial.print("TIME: ");
Serial.println(time);
while(1);
}
void loop()
{
}
takes less than a minute, 11 char takes 11 minutes, 12 -> 2 hours, 13 -> ~day, 14 -> 2 weeks, 15 -> half a year, 16 -> 8 years, 17 1.3 century, 18 -> 2 millenia, 19 -> period of modern man (~40.000 yrs) 20 -> 0.8 million years, 21 -> 16 million years, 22 -> 300 million years, 23 -> earths life, 24 -> beyond universe life.
AWOL:
Even if you did one combination per clock cycle, 2128 combinations is going to take a few billion years to compute.
Edit: About 673,931,095,284,769,880,043,505 years, or about 49,013,170,566,165 times the age of the Universe
He wants only to do 248 combinations. If one per usec => 9 years ?