Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 8th, 2005, 5:36 PM   #1
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
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');
	}
but that gives me a bunch of crap, and the other one I tried gave me all one-character, two-character, three-character, etc. combinations and I don't have the (processor) time to let that work out.

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;}
iignotus is offline   Reply With Quote
Old Jul 8th, 2005, 8:05 PM   #2
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
#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
stevengs is offline   Reply With Quote
Old Jul 8th, 2005, 9:47 PM   #3
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
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;}
iignotus is offline   Reply With Quote
Old Jul 9th, 2005, 7:53 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Why not just declare aa, ab, ac etc. as character variables instead of integers?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 9th, 2005, 4:54 PM   #5
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
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;}
iignotus is offline   Reply With Quote
Old Jul 10th, 2005, 7:00 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 10th, 2005, 7:25 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jul 10th, 2005, 7:36 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Yeah... that's what I meant. But still... why go out of your way to make your program more confusing?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC