Determine all possible pair(s) (M, X) of positive integers, with M - 1 > X > 1, such that the decimal representation of MCX consists of non leading zeroes and contains each of the digits 0 to 9 exactly once.
Note: MCX is the number of X-element subsets (the X-combinations) of an M-element set, that is the number of ways that X things can be 'chosen' from a set of M things.
The program will capture only the lower value of X for C(M,X) and C(M,M-X), as it will abandon a given M when the X's cause the combinations to go above a 10-digit number.
UBASIC will not calculate by itself C(M,X) when M > 65536, so this is done via the formula for X = 2. Further values of X are not required as C(65535,3) is already 46,908,201,271,295, a 14-digit number.
As C(141422,2) already exceeds 10 digits, we need go no farther with M.
Thus the results will be complete.
10 Lm=141422
20 for M=4 to Lm
30 for X=2 to M-2
35 if M>=65536 and X>2 then cancel for:goto *NotThis
40 if M<65536 then C=combi(M,X):else C=int(M*(M-1)/2)
50 if C>9999999999 then cancel for:goto *NotThis
60 Cs=cutspc(str(C))
65 Good=0
70 if len(Cs)=10 then
75 :Good=1
80 :for I=1 to 9
90 :if instr(I+1,Cs,mid(Cs,I,1))>0 then Good=0:endif
100 :next
110 if Good then print M;tab(12);X;tab(18);C:inc SCt
120 next X
125 *NotThis
130 next M
140 print SCt
There are 84 results; you could double this by setting X = M - X in each instance:
M X C(M,X)
253 5 8301429675
595 4 5169738420
46098 2 1062489753
49797 2 1239845706
50140 2 1256984730
55152 2 1520843976
55485 2 1539264870
56521 2 1597283460
58051 2 1684930275
62496 2 1952843760
62568 2 1957346028
62901 2 1978236450
66295 2 2197480365
68806 2 2367098415
69543 2 2418079653
70767 2 2503948761
72595 2 2634980715
73738 2 2718609453
73972 2 2735891406
74169 2 2750483196
74358 2 2764518903
75556 2 2854316790
76365 2 2915768430
77806 2 3026847915
78687 2 3095782641
78849 2 3108542976
84556 2 3574816290
85960 2 3694517820
86077 2 3704581926
87264 2 3807459216
87670 2 3842970615
88407 2 3907854621
89884 2 4039521786
90288 2 4075916328
90298 2 4076819253
90981 2 4138725690
91477 2 4183975026
91836 2 4216879530
93393 2 4361079528
93627 2 4382960751
95112 2 4523098716
96994 2 4703869521
97488 2 4751906328
97965 2 4798521630
98685 2 4869315270
98758 2 4876521903
99271 2 4927316085
99325 2 4932678150
99613 2 4961325078
100387 2 5038724691
100747 2 5074928631
101224 2 5123098476
101709 2 5172309486
104113 2 5419706328
104202 2 5428976301
104779 2 5489267031
107154 2 5740936281
107605 2 5789364210
107829 2 5813492706
109405 2 5984672310
110395 2 6093472815
112708 2 6351490278
114039 2 6502389741
117081 2 6853921740
117423 2 6894021753
118071 2 6970321485
120699 2 7284063951
121815 2 7419386205
122221 2 7468925310
122329 2 7482130956
125064 2 7820439516
125236 2 7841965230
126162 2 7958362041
128341 2 8235641970
130689 2 8539742016
131382 2 8630549271
133615 2 8926417305
133839 2 8956372041
133876 2 8961324750
134442 2 9037258461
135658 2 9201478653
138394 2 9576380421
138816 2 9634871520
138960 2 9654871320
|
Posted by Charlie
on 2009-04-28 12:28:47 |