Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matched pairs represented by triplets??
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00763480
Message ID:
00763501
Views:
16
Neil,

The number of combinations of 10 things taken 3 at a time is 10! / ( (10-3)! * 3! ) or 120.

this sql will give you all the permutations of N items taken 3 at a time:
create cursor x1 ( i1 i )
for i = 1 to 10
   insert into x1 values ( i )
endfor


select x1.i1, x2.i1, x3.i1 ;
   from x1 ;
   left join x1 as x2 on x1.i1 != x2.i1 ;
   left join x1 as x3 on x1.i1 != x3.i1 and x2.i1 != x3.i1 ;
   into cursor ThePermutations
given 10 items in x1 the result will have 720 rows because it considers 1,2,3 and 1,3,2 and 2,1,3 and 2,3,1 and 3,1,2 and 3,2,1 as distinct permutations, for combinations you don't care about the order so any one of those 6 results is all you want.
select x1.i1 as i1, x2.i1 as i2, x3.i1 as i3 ;
   from x1 ;
   left join x1 as x2 on x1.i1 < x2.i1 ;
   left join x1 as x3 on x1.i1 < x3.i1 and x2.i1 < x3.i1 ;
   into cursor TheCombinations ;
   having ! isnull( i2 ) and ! isnull( i3 )
This will eliminate the replications based on order and give you just the combinations.

>I have 10 comma delimited number pairs:
>
>I have 10 letters. Each of the letters can represent 3 of the of the comma delimited pairs. ie:
>
>
>How do I figure out the least number of letters that will represent all of the comma delimited number pairs. ie: I was able to eye ball the list and figure out that j,i,f,a will do it. But how do you program logic. How about representing the numbers in data tables and using joins and unions. Any takers?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform