Mathematik Prob (How many Combinations are possible ....
Mathematik Prob (How many Combinations are possible ....
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
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
Code: Select all
Procedure.l CalcPosibs(N.l)
Result.l = 1
For i.l = 1 To N
Result * i
Next i
ProcedureReturn Result
EndProcedure
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
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
That's the faculty.
An easy way (and the only exact known way) is just to do this multiplication step by step, so:
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. 
Code: Select all
n * (n-1) * (n-2) * ... * 2 * 1 = n!
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

%1>>1+1*1/1-1!1|1&1<<$1=1
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
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
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
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
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
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
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
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

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
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
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
THANK YOU !!!
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

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"

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