Mathematik Prob (How many Combinations are possible ....

Just starting out? Need help? Post your questions and find answers here.
guruk
User
User
Posts: 50
Joined: Thu Aug 18, 2005 2:05 pm

Mathematik Prob (How many Combinations are possible ....

Post by guruk »

How looks a Algorythm to do a 2, 6, 24 ...

Based on the Logic.. How many Combinations are possible when I have
how many Variables...

A
1

AB BC
2

ABC ACB BCA BAC CAB CBA
6

ABCD ... ...
24


How must a Procedure calculate to return:
CalcPosibs (3) = 6

Any Ideas
Christian
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

Code: Select all

Procedure.l CalcPosibs(N.l)
   Result.l = 1
   For i.l = 1 To N
      Result * i
   Next i
   ProcedureReturn Result
EndProcedure
How's that?
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

If you have n different letters and want to combine them with respecting their order you have n choices for the 1st letter, (n-1) for the 2nd, (n-2) for the 3rd, ... etc until 1 choice for the last letter. That's called "permutation without repetition". So you have

Code: Select all

n * (n-1) * (n-2) * ... * 2 * 1 = n!
That's the faculty.

An easy way (and the only exact known way) is just to do this multiplication step by step, so:

Code: Select all

Procedure.l Fac(n.l)
  If n < 0 or n > 12 ; 12 is the highest faculty for 32-bit-integer
    ProcedureReturn -1
  Endif

  Protected result.l, i.l
  result = 1
  for i=2 to n
    result * i
  next
  ProcedureReturn result
EndProcedure
Though there's a 'bad' simple loop inside the algorithm should be fast enough, because 13! is already 6227020800, so bigger than 32-bit-integer. :wink:
%1>>1+1*1/1-1!1|1&1<<$1=1
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post by kenmo »

Good points - N should be checked for negative, 13+ is too large for longs, and including 1 in my For-Next is unnecessary.
guruk
User
User
Posts: 50
Joined: Thu Aug 18, 2005 2:05 pm

Post by guruk »

Now How to produce a mix of possibs.

examble

Dim a$(10)

a$(0) = "Test"
a$(1) = "Hallo"
a$(2) = "Mich"
Anzahlkeywords = 3

Procedure createpossiblecombins (a$)
returnprocedure strwert$
EndProcedure

strwert$ = Createpossiblecombins (a$)

debug (strwert$)

We get in our Output:
Debug strwert$ //== "Test Hallo Mich, Test Mich Hallo, Mich Test hallo,
Mich Hallo Test, Hallo Mich Test, Hallo Test Mich"

My Prob is to make x Loops defined in a Loop..

Greets Chris
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

At purearea.net in the codearchiv under maths->geometry there's a codesnippet: PermutationsGenerator.pb that does the job:
http://www.purearea.net/pb/CodeArchiv/M ... nerator.pb
and here's another one:
http://forums.purebasic.com/german/viewtopic.php?t=953
%1>>1+1*1/1-1!1|1&1<<$1=1
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

guruk,
perhaps this code is useful to you:
viewtopic.php?t=17116
If you find it useful i transtlate it to english, just ask it to me :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
guruk
User
User
Posts: 50
Joined: Thu Aug 18, 2005 2:05 pm

Post by guruk »

you are both great.

thanks a lot you gave me right Code and with that I save a lot of time in research and development.

Now it comes on me to put it in a new Environment to do a new Product.

Its also I sometimes think about how to thank enough and right.
Is it enough to say "Thanks to all Members in Purebasic Forum"?

Maybe not ....

For now I only like to say / many thanks / and may all your new friends good.

Keep on supporting, and believing that when the right time, you also get supported.

</Phil End>

Regards
Christian
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Its also I sometimes think about how to thank enough and right.
Is it enough to say "Thanks to all Members in Purebasic Forum"?
Yes, of course. I think all of us give and get in this forum.
There's no need for saying more than 'thanks'. :wink:
%1>>1+1*1/1-1!1|1&1<<$1=1
guruk
User
User
Posts: 50
Joined: Thu Aug 18, 2005 2:05 pm

THANK YOU !!!

Post by guruk »

Very Interesting.. I did not found this Topic anymore when I was looking in Coding Questions, but when I searched.. I found it. Great :)

I was looking for it... only to tell you all THANK YOU.

Without you I think I would not find Time to realize it.

For that I did it as Freeware ! and included a Thanks to all Forum Members (you know specialy I think about)

It was a great small Job and when you like to see the Result
(hopefully not Offtopic) Check: http://www.guruk.com/shop/permutator .

"The Permutator" :) It happend like this. Its at all a simple KeyWord mixer for AdWords Keyword Combinations.

Not really the most perfect (when you click to calculate 8 to 10 Keywords.. it looks like that the System is crashed , because it needs so long). More than 10 is not allowed :)


Hopefully to see you again. You are all Specialists I see.

Kind regards
Christian
Post Reply