#Using Maple to check for 5-card Krypto hands #Save this part as infile and then type maple < infile > outfile S:=[`+`,`-`,`*`,`/`]: x1:=`X1`:x2:=`X2`:x3:=`X3`:x4:=`X4`:x5:=`X5`: for i to 4 do for j to 4 do for k to 4 do for l to 4 do lprint(x1||(S[i])||`(`||x2||(S[j])||`(`||x3||(S[k])||`(`||x4||(S[l])||x5||`)))`||`,`); lprint(x1||(S[i])||`(`||x2||(S[j])||`((`||x3||(S[k])||x4||`)`||(S[l])||x5||`))`||`,`); lprint(x1||(S[i])||`((`||x2||(S[j])||x3||`)`||(S[k])||`(`||x4||(S[l])||x5||`))`||`,`); lprint(x1||(S[i])||`((`||x2||(S[j])||`(`||x3||(S[k])||x4||`))`||(S[l])||x5||`)`||`,`); lprint(x1||(S[i])||`(((`||x2||(S[j])||x3||`)`||(S[k])||x4||`)`||(S[l])||x5||`)`||`,`); lprint(`(`||x1||(S[i])||x2||`)`||(S[j])||`(`||x3||(S[k])||`(`||x4||(S[l])||x5||`))`||`,`); lprint(`(`||x1||(S[i])||x2||`)`||(S[j])||`((`||x3||(S[k])||x4||`)`||(S[l])||x5||`)`||`,`); lprint(`(`||x1||(S[i])||`(`||x2||(S[j])||x3||`))`||(S[k])||`(`||x4||(S[l])||x5||`)`||`,`); lprint(`(`||x1||(S[i])||`(`||x2||(S[j])||`(`||x3||(S[k])||x4||`)))`||(S[l])||x5||`,`); lprint(`(`||x1||(S[i])||`((`||x2||(S[j])||x3||`)`||(S[k])||x4||`))`||(S[l])||x5||`,`); lprint(`((`||x1||(S[i])||x2||`)`||(S[j])||x3||`)`||(S[k])||`(`||x4||(S[l])||x5||`)`||`,`); lprint(`((`||x1||(S[i])||x2||`)`||(S[j])||`(`||x3||(S[k])||x4||`))`||(S[l])||x5||`,`); lprint(`((`||x1||(S[i])||`(`||x2||(S[j])||x3||`))`||(S[k])||x4||`)`||(S[l])||x5||`,`); lprint(`(((`||x1||(S[i])||x2||`)`||(S[j])||x3||`)`||(S[k])||x4||`)`||(S[l])||x5||`,`); od:od:od:od: #Then edit outfile to get the 14*4^4 =3584 lines shown, as infile2 : A:=[ X1+(X2+(X3+(X4+X5))), ...etc... ((X1/(X2/X3))/X4)/X5, (((X1/X2)/X3)/X4)/X5 ]: #Now read in infile2 and check for redundancies. #Note: we could pre-reduce the file with #B:={op(factor(A))}: # 1440 formulas instead of 3584 in A. But while they are distinct rational # functions, these are not all in different orbits under Sym(5). # In retrospect, I should've kept these factored forms, as we'll see... # We separate the 3584 formulas according to the sizes of these orbits. with(combinat): P:=permute(5); eva:=proc(f) {seq(subs({seq(X||i=x||(p[i]),i=1..5)},f),p = P)}: end: B:=[seq(eva(a), a=A)]: DL:={seq(nops(b),b=B)}; # {1, 5, 10, 15, 20, 30, 60, 120} B1:=[]:B5:=[]:B10:=[]:B15:=[]:B20:=[]:B30:=[]:B60:=[]:B120:=[]: for b in B do n:=nops(b):B||n:=[op(B||n),b]:od: nops(B1),nops(B5),nops(B10),nops(B15),nops(B20),nops(B30),nops(B60),nops(B120); # 28, 180, 424, 32, 368, 808, 1360, 384 #Now we can remove redundancies: C1:={op(B1)}:C5:={op(B5)}:C10:={op(B10)}:C15:={op(B15)}:C20:={op(B20)}:C30:={op(B30)}:C60:={op(B60)}:C120:={op(B120)}: #Return to being lists, not sets, to preserve order: for i in DL do C||i:=[op(C||i)]:od: nops(C1),nops(C5),nops(C10),nops(C15),nops(C20),nops(C30),nops(C60),nops(C120); # 2, 10, 22, 12, 46, 102, 258, 106 nops(C1)+nops(C5)+nops(C10)+nops(C15)+nops(C20)+nops(C30)+nops(C60)+nops(C120); # 558 -- a little too large! samp:=[3^3,5^5,7^7,11^11,13^13]; for i in DL do D||i:=subs({seq(x||j=samp[j],j=1..5)},C||i):od: for i in DL do {seq(nops(d),d=D||i)};od; #Shows that some formulas in last two sets have only half the expected number #of values. Indeed an examination shows they have been wrongly placed: for i to nops(D60) do if nops(D60[i])=30 then lprint(i,C60[i][1]) fi:od: #x5+(x3-x2)*(x4-x1) is _in this run_ formula C60[8][1], etc. #x5-(x2-x1)*(x4-x3) #(x1-x2)*(x4-x5)*x3 #(x2-x3)*(x4-x5)-x1 #(x1-x3)*(x2-x5)/x4 #x1/(x2-x4)/(x5-x3) bads:=[8,17,23,119,205,231]: #Warning: note first two ARE SAME; will fix below C30a:=[seq(C60[i],i=bads)]: for i to nops(D120) do if nops(D120[i])=60 then lprint(i,C120[i][1]) fi:od: #x1+(x2-x4)/(x3-x5) #(x4-x1)/(x2-x3)/x5 #x1-(x2-x3)/(x4-x5) #(x1-x3)*x4/(x5-x2) #(x3-x5)/(x2-x1)-x4 bads2:=[33,40,44,48,79]: C60a:=[seq(C60[i], i={seq(j,j=1..nops(C60))} minus {op(bads)})]: C60b:=[seq(C120[i],i=bads2)]: C120a:=[seq(C120[i], i={seq(j,j=1..nops(C120))} minus {op(bads2)})]: #Note: Applying 'factor' would have computed the true symmetry groups! #Numbers with symmetry group order given: # 2, 10, 22, 12, 46, 108, 257, 101 #Some pairs of formulas still not recognized as equal for i in DL do lprint(nops(C||i),nops({op(D||i)}));od: #2, 2 #10, 10 #22, 22 #12, 12 #46, 46 #102, 102 #258, 227 #106, 79 for i in DL do E||i:=C||i:od: E30:=[op(C30), op(factor(C30a))]:nops(E30); E60:=[op(C60a),op(factor(C60b))]:nops(E60); E120:=C120a:nops(E120); E60:={op(factor(E60))}:nops(E60); #not 257 now but 226 entries E120:={op(factor(E120))}:nops(E120); #not 257 now but entries nops(E1),nops(E5),nops(E10),nops(E15),nops(E20),nops(E30),nops(E60),nops(E120); # 2, 10, 22, 12, 46, 108, 226, 75 nops(E1)+nops(E5)+nops(E10)+nops(E15)+nops(E20)+nops(E30)+nops(E60)+nops(E120); #501 formulas. But we noted earlier that # x5+(x3-x2)*(x4-x1) ~ x5-(x2-x1)*(x4-x3), so it's really 500: #In this run, it's the 103rd and 104th elements of E30 which are the same: for i in DL do E||i:=[op(E||i)]:od: samp:=[3^3,5^5,7^7,11^11,13^13]; for i in DL do F||i:=subs({seq(x||j=samp[j],j=1..5)},E||i):od: for i in DL do lprint(nops(F||i), nops({op(F||i)})):od: E30:=[seq(E30[i], i=1..103), seq(E30[i],i=105..nops(E30))]: #Gather representatives: for i in DL do G||i:=[seq((E||i)[j][1],j=1..nops(E||i))]:od: seq(nops(G||i),i = DL); # 2, 10, 22, 12, 46, 107, 226, 75 #Here they are: for i in DL do for d in G||i do lprint(d) od:od: #Store in infile3 #The E's give all possible permutations among the G's add( nops(E||i)*i, i = DL); # 27142 #SO! We can test for solvability. samp:=[4,7,7,8,10]:targ:=24: for i in DL do for j to nops(E||i) do for k to i do f:=factor((E||i)[j][k]):d:=denom(f):n:=f*d: subs({seq(x||j=samp[j],j=1..5)},[n,d]): if %[2]<>0 then if %[1]/%[2]=targ then lprint(i,j,k,(E||i)[j][k]) fi: fi: od:od:od: #Here's an example I needed to try. #Let x1=4, x2=7, x3=7, x4=8, x5=10. Then the following formulas give 24, #and these are the only ones which do (apart from swapping x2 and x3): # #(x1+x2+x5)*x4/x3 = ( ( 4 + 7 + 10 ) / 7 ) x 8 #x4*x5-(x2+x3)*x1 = ( 8 x 10 ) - ( ( 7 + 7 ) x 4 ) #x1*(x2+x3-x5)+x4 = ( 4 x ( 7 + 7 - 10 ) ) + 8 #(x2+x3)*(x5-x4)-x1 = ( ( 7 + 7 ) x (10 - 8 ) ) - 4 #(x5/x3+x4/x1)*x2 = ( 10 / 7 + 8 / 4 ) x 7 # #Note that the last one would be prohibited by the rule requiring #intermediate results to remain integers. The first one we "should" #have gotten, but the others strike me as just a little convoluted. #Here are routines which will work from scratch. with(combinat): P:=permute(5); read infile3: E:={seq(seq(subs({seq(x||j=X||(P[k][j]), j=1..5)}, G[i]), k=1..120),i=1..500)}: samp:=[4,7,7,8,10]:targ:=24: for e in E do f:=factor(e):d:=denom(f):n:=f*d: subs({seq(X||j=samp[j],j=1..5)},[n,d]): if %[2]<>0 then if %[1]/%[2]=targ then lprint(e) fi: fi: od: