Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Finding all possible combinations?

Author
Message
xCept
23
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 30th Jul 2003 02:10
Hey group ,

I am not exactly new to DB or DBPro (I own both), but there is one thing that has been stumping me for about a week now. I can't seem to figure out aformula that will figure out all possible combinations that can be created using a set of numbers. For example:

The numbers: 12345

I want to be able to find all combinations and save them in an array (such as 12354, 12534, 15234, 51234, etc...) without having to manually enter all the possible combinations! Can anyone provide example code that would do such a thing? It seems like it wouldn't be hard to come up with something that works (and doesn't duplicate combinations) but I'm stuck. Thanks in advance!
UberTuba
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 30th Jul 2003 03:02 Edited at: 30th Jul 2003 03:02
number of numbers (5 for isntance factorial) (thats the ! maths symbol)
and now th english translation:
if u have the number 5 the answer will be 5*4*3*2*1
if u have 3 numbers the answer will be 3*2*1
and so on

the artist formally known as darkfluff
xCept
23
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 30th Jul 2003 03:26
Thanks for that bit of info (very good to know)! But now I still can't figure out actually 'how' to generate a list of all the different combonations. I actually want the entire list of different combo's to be saved in an array. Thanks again!

Ralen
22
Years of Service
User Offline
Joined: 22nd Jul 2003
Location:
Posted: 30th Jul 2003 07:07 Edited at: 30th Jul 2003 07:08
That is the best way I can think of doing that right off the type of my head. Hope that helps. There is no way to programmatically do this unless you made your own base 5 numbering system but I don't wanna try to explain how to do that.

If you really wanna know take a good TCP/IP class you learn all about base numbering systems in a good one. Probably doesn't make since now, but if you took it it would make perfect since

edit:bleh sorry for the type in the remarks of the code. Everything else should work though. Tested it myself before I posted it.

xCept
23
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 31st Jul 2003 03:38
Ralen, thanks for the example code. It works fine, except for the fact that I do not want any numbers to be repeated in each combonation. Right now it goes 11111, 11112, etc... I want it to be like 12345 12354 12534, and so on. Another example of what I'm looking for is:

ABC
ACB
BAC
BCA
CAB
CBA

So no letters/numbers repeat in any one combonation. I just spent the past three hours searching Google for permutation formulas and examples and I'm completely lost yet (all I can find is C++ examples too). Any more help is appreciated

kevil
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 31st Jul 2003 03:57
How bout this, it is probably not the best way to do this, but it works.

Kevil

xCept
23
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 31st Jul 2003 04:34
Thats excellent!!! I was trying a simular method using FOR...LOOPs but unfortunately I don't have enough brains to think it through enough like you did, so I never could accomplish it. Thank you VERY much, its exactly what I wanted.

Login to post a reply

Server time is: 2026-07-21 21:13:35
Your offset time is: 2026-07-21 21:13:35