SOLUTION: C-program to get 35 combinations of the variables 'xxxxyyy'

Algebra ->  Permutations -> SOLUTION: C-program to get 35 combinations of the variables 'xxxxyyy'      Log On


   



Question 830568: C-program to get 35 combinations of the variables 'xxxxyyy'
Answer by Edwin McCravy(20054) About Me  (Show Source):
You can put this solution on YOUR website!
I don't know C.  I program in LibertyBASIC. I copied and pasted my 
LibertyBASIC program below for the 35 distinguishable 
permutations of xxxxyyy.  I think you can translate it to C 
using my comment statements which begin with ' followed by 4 spaces.
I copied and pasted my output below the program:
-----------------------------------------------------
'    start with xxxxxxx
gosub 1
'    choose leftmost position p to change an x to a y in
for p=1 to 5
'    choose a 2nd position q right of position p to change an x to y in
for q=p+1 to 6:if q=p then 2
'    choose a 3rd position r right of q to change an x to y in
for r=q+1 to 7:if r=q or r=p then 3
'    change the three x's to y's
a$(p)="y":a$(q)="y":a$(r)="y"
'    increase the count and print it
count=count+1:print count;". ";
'    print the first 6 letters in a row after the count
for s=1 to 6: print a$(s);:next s
'    print the 7th letter at the end the row
print a$(7)
'    change back to xxxxxxx
gosub 1
'    get the next value of r and loop back up
3 next r
'    get the next value of q and loop back up
2 next q
'    get the next value of p and loop back up
next p
'    we're done if we get here. So we end so we won't crash into the subroutine
end
'    subroutine to change all 7 to x's
1 for n=1 to 7:a$(n)="x":next n:return

---------------------------------------------
Here is the output for the above LIBERTY BASIC program
1. yyyxxxx
2. yyxyxxx
3. yyxxyxx
4. yyxxxyx
5. yyxxxxy
6. yxyyxxx
7. yxyxyxx
8. yxyxxyx
9. yxyxxxy
10. yxxyyxx
11. yxxyxyx
12. yxxyxxy
13. yxxxyyx
14. yxxxyxy
15. yxxxxyy
16. xyyyxxx
17. xyyxyxx
18. xyyxxyx
19. xyyxxxy
20. xyxyyxx
21. xyxyxyx
22. xyxyxxy
23. xyxxyyx
24. xyxxyxy
25. xyxxxyy
26. xxyyyxx
27. xxyyxyx
28. xxyyxxy
29. xxyxyyx
30. xxyxyxy
31. xxyxxyy
32. xxxyyyx
33. xxxyyxy
34. xxxyxyy
35. xxxxyyy

Edwin