![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
All Combinations
I've not been able to write a program that produces only ten-letter strings with all combinations of them. I've tried:
for (aa = 32; aa < 127; ++aa)
{
o.put(char(aa));
for (ab = 32; ab < 127; ++ab)
{
o.put(char(ab));
for (ac = 32; ac < 127; ++ac)
{
o.put(char(ac));
for (ad = 32; ad < 127; ++ad)
{
o.put(char(ad));
for (ae = 32; ae < 127; ++ae)
{
o.put(char(ae));
for (af = 32; af < 127; ++af)
{
o.put(char(af));
for (ag = 32; ag < 127; ++ag)
{
o.put(char(ag));
for (ah = 32; ah < 127; ++ah)
{
o.put(char(ah));
for (ai = 32; ai < 127; ++ai)
{
o.put(char(ai));
for (aj = 32; aj < 127; ++aj)
{
o.put(char(aj));
}
}
}
}
}
}
}
}
}
o.put('\n');
}This is really more of a math problem; thank you for any help.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
#include <iostream>
using namespace std;
int main( int argc, char* argv[] )
{
int aa, ab, ac, ad, ae, af, ag, ah, ai, aj;
ostream o = cout;
for ( aa = 33; aa < 127; aa++ )
{
for ( ab = 33; ab < 127; ab++ )
{
for ( ac = 33; ac < 127; ac++ )
{
for ( ad = 33; ad < 127; ad++ )
{
for ( ae = 33; ae < 127; ae++ )
{
for ( af = 33; af < 127; af++ )
{
for ( ag = 33; ag < 127; ag++ )
{
for ( ah = 33; ah < 127; ah++ )
{
for ( ai = 33; ai < 127; ai++ )
{
for ( aj = 33; aj < 127; aj++ )
{
o << (char)aj
<< (char)ai
<< (char)ah
<< (char)ag
<< (char)af
<< (char)ae
<< (char)ad
<< (char)ac
<< (char)ab
<< (char)aa
<< endl;
}
}
}
}
}
}
}
}
}
}
return 0;
}
maybe?
takes a while (understandably ;) )
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Problem totally solved! Thank you. Quite honestly, that's what I had the first time around... you'll never believe the reason why I *thought* it didn't work
![]()
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Why not just declare aa, ab, ac etc. as character variables instead of integers?
|
|
|
|
|
|
#5 |
|
Professional Programmer
|
No reason, really Ooble; just a matter of preference.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It's more than a matter of preference. Using character variables would halve the memory used and stop you from having to cast ten variables to characters ten billion times.
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
A char actually only takes up one fourth the space of an int (on a 32-bit machine). They're often passed around as ints, so that they can be tested for error values. The casting is a compile time thangy and imposes no run-time penalty. Personally, like Ooble, I would have used a char. My system wouldn't have noticed the resource difference, though, comparatively speaking. The important thing is to get the algorithmic details down.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|