maths script - combinatorics

Job ID: 33020466

Budget: $30 – $250 USD

i want to write a maths script or program using php which will calculate/count the possible permutations from a given binary number (consisting of 0 and 1) . compute the binary string and then we need to group them in sets according to certain rules

The program will ask for the number of digits e.g 3 which is N and then the number of 1s eg. 2 which is R. so we need to work out two things
NcR = 3c2 = 3!/2!.1! = 3

to understand this ill give a very basic example.
so in this example
N =3 (total 0s and 1s)
R =2 (total 1s)
we could write the binary string as 110, 101, 011.

Group rules.
The groups are basically cycles of permuations/binary strings. if we start from any number in a group we eventually get back to that number through repeated application of the rules.

Rules:
1. start with a binary number e.g 110
2. MOVE the FIRST DIGIT to the END. (we get 101)
3. OUTPUT the new binary number (here its 101)
4. If the new output has already been outpuuted we ignore it and stop otherwise weRepeat steps 2 and 3 ad infinitum.

so here we have 110 , 101, 011 then 110 we are back to 110 so we STOP as we already had it before at the start
and this is all the possibilites as we know 3c2 = 3
so the full answer is

Total possible binary strings = 3c2 = 3.
1 x Group of length 3 (110 101 011)

Note: the total possible binary strings = the sum of the lengths of all the groups
here 3 = 3 is obvious.

lets try another lets try n=4 r = 2
Binary Strings = 4c2 = 6

1100 1001 0011 0110 ( 1 group of length 4) .... 0110 goes to 1100 so we stop
1010 0101 ( 1 group of length 2) .... 0101 goes to 1010 so we stop

this is it so we have 1x4 + 1x2 = 6 as expected.

so if i enter N = 4 and R = 2 in the 2 boxes the output will be

1100 1001 0011 0110 ( 1 group of length 4)
1010 0101 ( 1 group of length 2)

for N = 3 R = 2 the output was

110 101 011 (1 group of length 3)

no time wasters please
Related categories: PHP C Programming JavaScript Python Mathematics