Re: Solve - takes very long time
- To: mathgroup at smc.vnet.net
- Subject: [mg121830] Re: Solve - takes very long time
- From: Peter Pein <petsie at dordos.net>
- Date: Tue, 4 Oct 2011 01:32:09 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j6bris$8m4$1@smc.vnet.net>
Am 03.10.2011 10:26, schrieb Fredob: > Hi, > > I tried the following on Mathematica 8 and it doesn't seem to stop > running (waited 40 minutes on a 2.6 Ghz processor w 6 GB of primary > memory). > > Solve[ > {100*Subscript[x, 2] + 10*Subscript[x, 1] + Subscript[x, 0] + > 100*Subscript[y, 2] + 10*Subscript[y, 1] + Subscript[y, 0] == > 100*Subscript[z, 2] + 10*Subscript[z, 1] + Subscript[z, 0], > Subscript[x, 0]> 0, Subscript[y, 0]> 0, Subscript[z, 0]> 0, > Subscript[x, 1]> 0, Subscript[y, 1]> 0, Subscript[z, 1]> 0, > Subscript[x, 2]> 0, Subscript[y, 2]> 0, Subscript[z, 2]> 0, > Subscript[x, 0]<= 9, Subscript[y, 0]<= 9, Subscript[z, 0]<= 9, > Subscript[x, 1]<= 9, Subscript[y, 1]<= 9, Subscript[z, 1]<= 9, > Subscript[x, 2]<= 9, Subscript[y, 2]<= 9, Subscript[z, 2]<= 9, > Subscript[x, 0] != Subscript[y, 0] != Subscript[z, 0] != Subscript[ > x, 1] != Subscript[y, 1] != Subscript[z, 1] != Subscript[x, 2] != > Subscript[y, 2] != Subscript[z, 2]}, > {Subscript[x, 2], Subscript[y, 2], Subscript[z, 2], Subscript[x, 1], > Subscript[y, 1], Subscript[z, 1], Subscript[x, 0], Subscript[y, 0], > Subscript[z, 0] }, > Integers] > > The problem was a homework for my daugther where you are supposed to > use all digits to build - but only once - 2 three digit numbers and > addition. > > Hi, so you want to pick some of the permutations of {1,2,...,9}? Mathematica can do this very fast. In[1]:= Length[allsoln=Pick[#,#.{100,10,1,100,10,1,-100,-10,-1},0]&[Permutations[Range[9]]]]//AbsoluteTiming Out[1]= {0.032373,336} Shall your daughter give all solutions (then a computer printout should be accepted ;-)) Just to print three of the 336 solutions (first, middle, last sol.): In[2]:= MatrixForm[Partition[#,3]]&/@allsoln[[{1,168,-1}]] Out[2]= {(1 2 4 6 5 9 7 8 3 ), (3 4 2 5 7 6 9 1 8 ), (7 8 4 1 5 2 9 3 6 )} Peter