Page 1 of 1
Mathematik Prob (How many Combinations are possible ....
Posted: Wed Nov 09, 2005 9:04 pm
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
Posted: Wed Nov 09, 2005 9:43 pm
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?
Posted: Wed Nov 09, 2005 9:45 pm
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.

Posted: Wed Nov 09, 2005 9:56 pm
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.
Posted: Wed Nov 09, 2005 10:06 pm
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
Posted: Thu Nov 10, 2005 10:39 am
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
Posted: Thu Nov 10, 2005 12:00 pm
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

Posted: Thu Nov 10, 2005 12:38 pm
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
Posted: Thu Nov 10, 2005 2:24 pm
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'.

THANK YOU !!!
Posted: Fri Nov 11, 2005 5:30 pm
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