Jump to content
  • Advertisement
Sign in to follow this  
DarkSlayer

Permutations

This topic is 5444 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
Original post by Dmytry
26! is somewhere about 4*1026 , so, i think , anything will take alot of time... say if it can print 108 permutations per second (it certanly can't, i would be surprised if it can print 1000 per second on windows console!)....

Even if it'll print 108 per second, it will take about 100 billions years(alot longer than existence of universe) to show all permutations, if i'm right.[grin]
(edit:had mistake with orders-of-magnitude, fixed.)


...OK, bad example, but when I started it just to see what happened, it did a couple hundred or thousand and then paused for at least 20 minutes before I quit it.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by Nathaniel Hammen
Quote:
Original post by Dmytry
26! is somewhere about 4*1026 , so, i think , anything will take alot of time... say if it can print 108 permutations per second (it certanly can't, i would be surprised if it can print 1000 per second on windows console!)....

Even if it'll print 108 per second, it will take about 100 billions years(alot longer than existence of universe) to show all permutations, if i'm right.[grin]
(edit:had mistake with orders-of-magnitude, fixed.)


...OK, bad example, but when I started it just to see what happened, it did a couple hundred or thousand and then paused for at least 20 minutes before I quit it.

i looked at your code and understood what you mean - you check every combination and it's slower than other methods (except that, for 26 letters it doesn't matter anyway[grin])

How i'd do it:
make an array of unique letters and counts of 'em
(say,for `mississippi' it will be
m 1
i 4
s 4
p 2
,
then in pseudocode(almost compilable)(i can complete if you need)

struct same_letters{
unsigned char c;
int count;
}
same_letters arr[26];
int arrlength;
#define MAX_STRING_SIZE 256
char str[MAX_STRING_SIZE];
int strlength=0;
void recursive_function(){
for(n=0;n<arrlength;n++)// it's possible to speed-up that piece of code but i don't sure it's reasonable.
if(arr[n].count)
{
str[strlength]=arr[n].c;
strlength++;
if(strlength<length_of_original_string){
arr[n].count--;
recursive_function();
arr[n].count++;
} else { printf(str); }
strlength--;
}//for() if
}
main{
Read input;
prepare arr[] and arrlength, it's trivial;
recursive_function();
};


btw, i hope it's not homework?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!