# How can I solve this integer equation with Mathematica?

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

• Brute force should suffice for this. – Daniel Lichtblau Jan 8 '17 at 21:40
• @DanielLichtblau That's $9^9$ combinations. – Feyre Jan 8 '17 at 21:50
• @Feyre No, only $9!$ since all are pairwise unequal. – Daniel Lichtblau Jan 8 '17 at 21:52
• @DanielLichtblau So much for my reading comprehension. – Feyre Jan 8 '17 at 22:04
• @Corey979 Not really related though your approach is in each case (and I upvoted both). The salient difference is that, as best I can tell, today's question cannot be cast as an integer linear program (ILP, emphasis on the L). So it is not clear that there is any alternative to brute force. Well, not clear to me at least. – Daniel Lichtblau Jan 8 '17 at 22:28

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]]