I have to solve this equation, where each variable is an integer from 1-9, but every variable has a different value:
(a/(10 b+c))+(d/(10 e+f))+(g/(10 h+i)) == 1
I have to solve this equation, where each variable is an integer from 1-9, but every variable has a different value:
(a/(10 b+c))+(d/(10 e+f))+(g/(10 h+i)) == 1
There are 9! == 362880
combinations (because every variable has a different value) so we can check all of them.
p = Permutations @ Range @ 9;
pos = Flatten @
Position[(#1/(10 #2 + #3) + #4/(10 #5 + #6) + #7/(10 #8 + #9) == 1) & @@@ p, True]
{173225, 173403, 271265, 271325, 322803, 323135}
p[[pos]]
{{5, 3, 4, 7, 6, 8, 9, 1, 2}, {5, 3, 4, 9, 1, 2, 7, 6, 8}, {7, 6, 8, 5, 3, 4, 9, 1, 2}, {7, 6, 8, 9, 1, 2, 5, 3, 4}, {9, 1, 2, 5, 3, 4, 7, 6, 8}, {9, 1, 2, 7, 6, 8, 5, 3, 4}}
Hence, there are six solutions as listed above.
More compactly (but requiring about 20% more time):
s = Select[Permutations @ Range @ 9,
#1/(10 #2 + #3) + #4/(10 #5 + #6) + #7/(10 #8 + #9) & @@ # == 1 &]
p[[pos]] == s
True
ListLinePlot @ s
With[{perm = Permutations@Range@9},
Pick[perm, (#1/(10. #2 + #3) + #4/(10. #5 + #6) + #7/(10. #8 + #9) - 1) &
@@ Transpose@perm // Unitize, 0]]