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 / Like nCr or nPr (Math - Probability)

Author
Message
Gamefreak
20
Years of Service
User Offline
Joined: 20th Jun 2004
Location: Cyberspace
Posted: 30th Jun 2005 09:55
You know the nCr and nPr functions on a graphing calculator, they give you the # of possibled combinations of a set of #'s?

Is it possible to make a program that will print out all these combinations when you enter a string?

I would want it to print for "ab" both "ab"(obviously) and "ba"
AndLabs
20
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 30th Jun 2005 10:08
We don't understand what you mean, but you can mock permutations (nPr) and combinations (nCr), both probability. You would need the probability FACTORIAL (n!) function in order to do nCr.

Here is a mock set of functions for both:



If you find any problem with the code, just tell us.

For the Software You Want, AMPERSAND LABORATORIES is the place!
Gamefreak
20
Years of Service
User Offline
Joined: 20th Jun 2004
Location: Cyberspace
Posted: 30th Jun 2005 10:22
Help making something like:

Type in: ABC

Returns:
AAA, AAB, AAC
ABA, ABB, ABC
ACA, ACB, ACC

BAA, BAB, BAC
BBA, BBB, BBC
BCA, BCB, BCC

CAA, CAB, CAC
CBA, CBB, CBC
CCA, CCB, CCC

All the combinations
AndLabs
20
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 30th Jun 2005 10:29
Whoops!

Wow! That's a little too high-end for string manipulation!

Because functions can't return arrays, this example will return a string with items seperated by spaces. This only works with 2-letter strings. If there is a problem, this function will return an empty string.



The idea is basic: swap the characters. This function will also return the first string as the first item.

You could build on top of this, to expand it a little. We'll contact you again the moment we crack the 3-letter code.

For the Software You Want, AMPERSAND LABORATORIES is the place!
Briere
20
Years of Service
User Offline
Joined: 28th Feb 2005
Location: Amherst New York, United States
Posted: 30th Jun 2005 13:25
What happends when I type in ABCDEFGHIJKLMNOPQRSTUVWXYZ



here is a theory that i would use, may be good, may not be good.

Make an array, read the first letter of the string. delete it from the string and store the fist letter in index 0. Then read the next string and keep going, while checking to make sure you dont have doubles, unless you are counting them.

As for ordering them, that will be very hard when dealing with people like me who like to use the whole alphabet

you would need an array with a whole lot of dimensions and some way to check for the end of the strings left.

Formerly The Fixxer
http://www.xiemsoft.cjb.net
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 1st Jul 2005 06:33 Edited at: 1st Jul 2005 06:33
you need to use multiple loops, say you want to take 3 letters from a group in every possible way includign abc and cba as different
loop through like so:

loop through letter 1 to last
loop through letter 1 to last
loop through letter 1 to last
print letter from first loop, letter from second, letter from third
endloop
endloop
endloop


if you want abc and acb to be counted as not different
(as in nCr):


http://www.larinar.tk
AMD athlon 64 3000+, 512mb ddr400, abit kv8, 160gb hdd, gigabit lan, ati radeon 9800se 128mb.
Jake Blues
20
Years of Service
User Offline
Joined: 19th Jun 2004
Location: United States
Posted: 1st Jul 2005 06:50 Edited at: 1st Jul 2005 08:27
This only half works but you could fix it up to work right.



RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 1st Jul 2005 23:28 Edited at: 1st Jul 2005 23:30
Something like this will work for 3 to 4 letter combos. What you really want to do is to make a recursive function (calls itself). This way the length of the string can be any length, not just 3 or 4 letters.



"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Jake Blues
20
Years of Service
User Offline
Joined: 19th Jun 2004
Location: United States
Posted: 2nd Jul 2005 01:53
This might not give all the combinations of the letters you give it and it does repeat some combinations, but it works for any amount of letters.



AndLabs
20
Years of Service
User Offline
Joined: 7th Dec 2004
Location:
Posted: 3rd Jul 2005 12:19
Our example was just a base for a more complex version.

For the Software You Want, AMPERSAND LABORATORIES is the place!

Login to post a reply

Server time is: 2025-05-29 20:20:31
Your offset time is: 2025-05-29 20:20:31