Re: Solve - takes very long time
- To: mathgroup at smc.vnet.net
- Subject: [mg121824] Re: Solve - takes very long time
- From: "Dr. Wolfgang Hintze" <weh at snafu.de>
- Date: Tue, 4 Oct 2011 01:31:04 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j6bris$8m4$1@smc.vnet.net>
"Fredob" <fredrik.doberl at gmail.com> schrieb im Newsbeitrag news:j6bris$8m4$1 at smc.vnet.net... > 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. > > Even the simplest operation of the type Reduce[eq, x>0] takes very long time also on my PC. It might be better to look for a different approach to the problem. I understand you are looking for three numbers A={a,b,c},B={d,e,f},C={g,h,i} such that (1) A+B = C and (2) {a,b, ...,i} = Permutation {1,2, ...,9} There are 168 different solutions (i.e. with A<B), These are the 4 with the smallest C (=459) {186, 273, 459}, {183, 276, 459}, {176, 283, 459}, {173, 286, 459} these are the 8 with the largest C (=981) {357, 624, 981}, {354, 627, 981}, {327, 654, 981}, {324, 657, 981}, {246, 735, 981}, {245, 736, 981}, {236, 745, 981}, {235, 746, 981} The code I used for finding all solutions is p=FromDigits/@(Partition[#, 3] & /@ Permutations[Range[9]]); (* form all possible sets of three 3-digit numbers *) sp = Select[p, #[[1]] + #[[2]] == #[[3]] &]; (* the equation *) sp1 = Select[sp, #[[1]] < #[[2]] &]; (* no repetition *) Reverse /@ Sort[Reverse /@ sp1] (* sort according to sum *) Wolfgang