Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5339 > unrolled thread
| Started by | Fredob <fredrik.doberl@gmail.com> |
|---|---|
| First post | 2011-10-03 08:26 +0000 |
| Last post | 2011-10-05 08:06 +0000 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Solve - takes very long time Fredob <fredrik.doberl@gmail.com> - 2011-10-03 08:26 +0000
Re: Solve - takes very long time Ray Koopman <koopman@sfu.ca> - 2011-10-04 05:33 +0000
Re: Solve - takes very long time "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-04 05:33 +0000
Re: Solve - takes very long time Peter Pein <petsie@dordos.net> - 2011-10-04 05:36 +0000
Re: Solve - takes very long time DrMajorBob <btreat1@austin.rr.com> - 2011-10-05 08:06 +0000
| From | Fredob <fredrik.doberl@gmail.com> |
|---|---|
| Date | 2011-10-03 08:26 +0000 |
| Subject | Solve - takes very long time |
| Message-ID | <j6bris$8m4$1@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.
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-10-04 05:33 +0000 |
| Message-ID | <j6e5qm$kap$1@smc.vnet.net> |
| In reply to | #5339 |
On Oct 3, 1:26 am, Fredob <fredrik.dob...@gmail.com> wrote:
> 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.
For each of the 42 solutions found by the brute force search given
below there are seven other solutions that may be obtained by
interchanging x0,y0 and/or x1,y1 and/or x2,y2.
FromDigits/@Partition[#,3]& /@ Select[Permutations@Range@9,
#[[1]] < #[[4]] && #[[2]] < #[[5]] && #[[3]] < #[[6]] &&
#.{100,10,1,100,10,1,-100,-10,-1} == 0 &]
{{124,659,783}, {125,739,864}, {127,359,486},
{127,368,495}, {128,439,567}, {134,658,792},
{142,596,738}, {142,695,837}, {143,586,729},
{152,487,639}, {152,784,936}, {162,387,549},
{162,783,945}, {173,286,459}, {173,295,468},
{182,394,576}, {182,493,675}, {214,569,783},
{214,659,873}, {215,478,693}, {215,748,963},
{216,378,594}, {216,738,954}, {218,349,567},
{218,439,657}, {234,657,891}, {235,746,981},
{241,596,837}, {243,576,819}, {243,675,918},
{251,397,648}, {271,593,864}, {271,683,954},
{281,394,675}, {314,658,972}, {317,529,846},
{317,628,945}, {324,567,891}, {324,657,981},
{341,586,927}, {342,576,918}, {352,467,819}}
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2011-10-04 05:33 +0000 |
| Message-ID | <j6e5rl$kbf$1@smc.vnet.net> |
| In reply to | #5339 |
"Fredob" <fredrik.doberl@gmail.com> schrieb im Newsbeitrag
news:j6bris$8m4$1@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
[toc] | [prev] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-10-04 05:36 +0000 |
| Message-ID | <j6e61c$kcj$1@smc.vnet.net> |
| In reply to | #5339 |
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
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-10-05 08:06 +0000 |
| Message-ID | <j6h35d$70h$1@smc.vnet.net> |
| In reply to | #5339 |
The conditions #[[2]] < #[[5]] and #[[3]] < #[[6]] do not belong, however.
Bobby
On Tue, 04 Oct 2011 00:30:53 -0500, Ray Koopman <koopman@sfu.ca> wrote:
> On Oct 3, 1:26 am, Fredob <fredrik.dob...@gmail.com> wrote:
>> 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.
>
> For each of the 42 solutions found by the brute force search given
> below there are seven other solutions that may be obtained by
> interchanging x0,y0 and/or x1,y1 and/or x2,y2.
>
> FromDigits/@Partition[#,3]& /@ Select[Permutations@Range@9,
> #[[1]] < #[[4]] && #[[2]] < #[[5]] && #[[3]] < #[[6]] &&
> #.{100,10,1,100,10,1,-100,-10,-1} == 0 &]
>
> {{124,659,783}, {125,739,864}, {127,359,486},
> {127,368,495}, {128,439,567}, {134,658,792},
> {142,596,738}, {142,695,837}, {143,586,729},
> {152,487,639}, {152,784,936}, {162,387,549},
> {162,783,945}, {173,286,459}, {173,295,468},
> {182,394,576}, {182,493,675}, {214,569,783},
> {214,659,873}, {215,478,693}, {215,748,963},
> {216,378,594}, {216,738,954}, {218,349,567},
> {218,439,657}, {234,657,891}, {235,746,981},
> {241,596,837}, {243,576,819}, {243,675,918},
> {251,397,648}, {271,593,864}, {271,683,954},
> {281,394,675}, {314,658,972}, {317,529,846},
> {317,628,945}, {324,567,891}, {324,657,981},
> {341,586,927}, {342,576,918}, {352,467,819}}
>
--
DrMajorBob@yahoo.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web