MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re:Playing with numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50228] Re: [mg50223] Re:[mg50135] Playing with numbers
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sun, 22 Aug 2004 00:19:37 -0400 (EDT)
  • References: <200408210704.DAA24819@smc.vnet.net> <opsc3o91yziz9bcq@monster.cox-internet.com> <opsc3siv10iz9bcq@monster.cox-internet.com>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

And now, let's look at only NINE cases.

As in the 18-case solution, one of {a,d,i} must be 1 and {b,f,g} is a permutation of {2,3,4}, and we get these general solutions:

conditions = Simplify@{h - f == i, f*g == c, e == f*b, a + b == h, c - d == a}
chooseOne[x_] := {a, b, c, d, e,
    f, g, h, i} /. First@Solve[conditions, Complement[{a, c, d, e,
       h, i}, {x}]] /. x -> 1
chooseOne/@{a,d,i}//ColumnForm

{{1,b,f g,-1+f g,b f,f,g,1+b,1+b-f},
{-1+f g,b,f g,1,b f,f,g,-1+b+f g,-1+b-f+f g},
{1-b+f,b,f g,-1+b-f+f g,b f,f,g,1+f,1}}

Then, as in the 24-case solution, we argue that h>=6. In the first solution above, h==1+b, but b<=4, so that's not a solution. In the third solution above, h==1+f, but f<=4, so that's not a solution. That leaves only the middle solution, d==1. (This argument is actually evident from the original equations, WITHOUT using the solutions above.)

Applying that to all six permutations of {2,3,4} makes 9 cases we've had to examine, and we get:

Select[chooseOne[d] /. Thread[{b, f, g} -> #] & /@ Permutations@{2, 3, 4},
     Union@# == Range@9 &]

{{5,4,6,1,8,2,3,9,7}}

Bobby

On Sat, 21 Aug 2004 17:24:21 -0500, DrBob <drbob at bigfoot.com> wrote:

> And here's a solution that checks only 18 cases that, still, is no more difficult to analyze than before.
>
> conditions = Simplify@{h - f == i, f*g == c, e == f*b, a + b == h, c - d == a}
> {f + i == h, c == f g, e == b f, a + b == h, a + d == c}
>
> (1) Because all nine symbols must be distinct, those involved in product or quotient equations -- b, c, e, f, and g -- cannot be 1. Nor can the sums c and h. Hence one of {a, d, i} must be 1 (three possibilities).
>
> (2) Therefore, 2 <= g == c/f <=c/2 <= 4. The same argument applies to f and b, so {b,f,g} is a permutation of {2,3,4}.
>
> If one of {a,d,i} is chosen to be 1 we can solve for the other five variables (other than that variable and b, f, g). This reduces the number of cases to
>
> 3*3!
>
> 18
>
> chooseOne[x_] := {a, b, c, d, e, f, g, h, i} /. First@Solve[conditions, Complement[{a, b, c, d,
>        e, f, g, h, i}, {b, f, g, x}]] /. x -> 1
> chooseOne /@ {a, d, i}
>
> {{1,b,f g,-1+f g,b f,f,g,1+b,1+b-f},{-1+f g,b,f g,1,b f,f,g,-1+b+f g,-1+
>    b-f+f g},{1-b+f,b,f g,-1+b-f+f g,b f,f,g,1+f,1}}
>
> solution[s_List, {bx_, fx_, gx_}] := Module[{sol = s /. Thread[{b, f, g} -> {bx, fx, gx}]},
>      If[Union@sol == Range@9, sol, {}]    ]
> Flatten[Outer[solution, chooseOne /@ {a, d, i} //
>      Evaluate, Permutations@{2, 3, 4}, 1], 1] /. {} -> Sequence[]
>
> {{5, 4, 6, 1, 8, 2, 3, 9, 7}}
>
> Bobby
>
> On Sat, 21 Aug 2004 16:14:15 -0500, DrBob <drbob at bigfoot.com> wrote:
>
>> That's pretty cool! It looks at 45 cases, though; I have a solution that looks at 24, with a pre-coding analysis that's no more onerous (I think).
>>
>> conditions = {h - f == i, f*g == c, e == f*b, a + b == h, c - d == a};
>>
>> Note g == c/f <= c/2 <= 4. Also g >= 2 as otherwise c == f. The same argument applies to f and b. Hence {b,f,g} is a permutation of {2,3,4}.
>>
>> Given that, we try solving for the other six variables. But Solve can get only five (there are five equations).
>>
>> First[Solve[conditions, {a, c, d, e, i}]];
>> simpleSolve = {a, b, c, d, e, f, g, h, i} /. %
>> {-b + h, b, f*g, b + f*g - h, b*f, f, g, h, -f + h}
>>
>> Note that four of these depend on h. The sums h==f+i==a+b imply that h is strictly greater than a, b, i, and f. Since {b, f, g} is a permutation of {2,3,4}, at least one of a and i must be bigger than four. Hence h>=6.
>>
>> Therefore, the number of possible solutions reduces to:
>>
>> 3!4
>>
>> 24
>>
>> In particular, the possible values of {b, f, g, h} are:
>>
>> bfgh = Flatten[Outer[Flatten@{#1, #2} &, Permutations@{2, 3, 4}, Range[6, 9], 1], 1];
>>
>> Finally we check all 30 cases and list the solutions:
>>
>> check@{bx_, fx_, gx_, hx_} := Module[
>>      {s = simpleSolve /. Thread[{b, f, g, h} -> {bx, fx, gx, hx}]},
>>      If[Sort@s == Range@9, s, {}]]
>> check /@ bfgh /. {} -> Sequence[]
>>
>> {{5, 4, 6, 1, 8, 2, 3, 9, 7}}
>>
>> That's a lot better than looking at 9!==362880 solutions!!
>>
>> Bobby
>>
>> On Sat, 21 Aug 2004 03:04:29 -0400 (EDT), Fred Simons <f.h.simons at tue.nl> wrote:
>>
>>> The question is to solve with Mathematica the set of equations
>>> (1) H - F = I
>>> (2) F x G = C
>>> (3) E / B = F
>>> (4) A + B = H
>>> (5) C - D = A
>>> where every variable from A to I stands for a number from 1 to 9 and each
>>> number appears only once.
>>>
>>> Here is a solution where Mathematica does the computations that we otherwise
>>> had to do by hand.
>>>
>>> Since the symbols represent different integers between 1 and 9, we conclude
>>> from the equations i+f=h, a+b=h that h has to be at least 5. From the
>>> equations c=f*g, e=f*b we conclude that f is between 2 and 4, that g is at
>>> least 2, that e is at least 2, that c is at least 6 and that e is at least
>>> 6.
>>>
>>> Given values for f, h, c and e, we can compute the other variables. The
>>> result has to be a permutation of the numbers 1, ..., 9.
>>>
>>> In[21]:= solution = {a, b, c, d, e, f, g, h, i} /.
>>> Solve[{h - f == i, f*g == c, e/b == f,
>>> a + b == h, c - d == a}, {a, b, d, g, i}][[1]]
>>>
>>> Out[21]=
>>> {-((e - f*h)/f), e/f, c, c + e/f - h, e, f, c/f, h, -f + h}
>>>
>>> In[23]:=
>>> Timing[Do[If[Length[Union[solution]] == 9,
>>> Print[solution]], {f, 2, 4},
>>> {c, Ceiling[5/f]*f, 9, f}, {e, Ceiling[5/f]*f, 9, f}, {h, 5, 9}]]
>>>
>>>> From In[23]:=
>>> {5,4,6,1,8,2,3,9,7}
>>>
>>> Out[23]=
>>> {0. Second,Null}
>>>
>>> So indeed there is only one solution.
>>>
>>> Fred Simons
>>> Eindhoven University of Technology
>>>
>>>
>>>
>>
>>
>>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Re:Playing with numbers
  • Next by Date: A Functional Measure of Roughness
  • Previous by thread: Re: Re:Playing with numbers
  • Next by thread: FindMinimum and the minimum-radius circle