MathGroup Archive 2003

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

Search the Archive

Re: Re: Solving Alphametics with Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38684] Re: [mg38640] Re: [mg38638] Solving Alphametics with Mathematica
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Sat, 4 Jan 2003 07:27:32 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I evaluated the notebook below in a fresh kernel and this time it 
worked perfectly. I had to pinch myself to confirm I was not dreaming, 
but I can swear it did not work yesterday.

Andrzej



(************** Content-type: application/mathematica **************
                      CreatedBy='Mathematica 4.2'

                     Mathematica-Compatible Notebook

This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do
one of the following:

* Save the data starting with the line of stars above into a file
   with a name ending in .nb, then open the file inside the
   application;

* Copy the data starting with the line of stars above to the
   clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.

For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
   web: http://www.wolfram.com
   email: info at wolfram.com
   phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      3922,        109]*)
(*NotebookOutlinePosition[      4579,        132]*)
(*  CellTagsIndexPosition[      4535,        128]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[BoxData[{\(<< NumericalMath`NMinimize`;\), "\[IndentingNewLine]",

     StyleBox[\(eq =
           10^3\ b\  + \ 10^2\ a\  + 10\ s + \ e + 10^3\ b\  + \
             10^2  a + 10  l + l - 10^4  g - 10^3  a - 10^2  m -
             10  e - s;\),
       FontFamily->"Monaco",
       FontSize->10], "\[IndentingNewLine]", \(ss =
         And @@ Union[
             DeleteCases[
               Flatten[
                 Outer[Abs[#1 - #2] \[GreaterEqual] 1 &,
                   Variables[eq], Variables[eq]]], False],
             SameTest \[Rule] \((TrueQ[
                     Simplify[
                       First[#1] \[Equal]
                         First[#2]]] &)\)];\)}], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
     StyleBox[\(NMinimize[{Abs[eq], \
           a\  == \ 4\  && \
             0\  <= \ b\  <= \ 9\  && \n\ \ \ \ \ \ 0\  <= \ e\  <= \
               9\  && \ 1\  <= \ g\  <= \ 9\  && \
             0\  <= \ l\  <= \ 9\  && \n\ \ \ \ \ \ 0\  <= \ m\  <= \
               9\  && \ 0\  <= \ s\  <= \ 9\  && \
             ss\  && \n\ \ \ \ \ \ Element[
               a\  | \ b\  | \ e\  | \n\ \ \ \ \ \ \ \ g\  | \ l\  | \
                 m\  | \ s\ , \ Integers]}, \ Variables[eq]]\),
       FontFamily->"Monaco",
       FontSize->10]], "Input"],

Cell[BoxData[
     \({0.`, {a \[Rule] 4, b \[Rule] 7, e \[Rule] 3, g \[Rule] 1,
         l \[Rule] 5, m \[Rule] 9, s \[Rule] 8}}\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
     StyleBox[\(NMinimize[{Abs[eq], \
           0 <= a <= 9\  && \
             1\  <= \ b\  <= \ 9\  && \n\ \ \ \ \ \ 0\  <= \ e\  <= \
               9\  && \ 1\  <= \ g\  <= \ 9\  && \
             0\  <= \ l\  <= \ 9\  && \n\ \ \ \ \ \ 0\  <= \ m\  <= \
               9\  && \ 0\  <= \ s\  <= \ 9\  && \
             ss\  && \n\ \ \ \ \ \ Element[
               a\  | \ b\  | \ e\  | \n\ \ \ \ \ \ \ \ g\  | \ l\  | \
                 m\  | \ s\ , \ Integers]}, \ Variables[eq]]\),
       FontFamily->"Monaco",
       FontSize->10]], "Input"],

Cell[BoxData[
     \({0.`, {a \[Rule] 4, b \[Rule] 7, e \[Rule] 3, g \[Rule] 1,
         l \[Rule] 5, m \[Rule] 9, s \[Rule] 8}}\)], "Output"]
}, Open  ]]
},
FrontEndVersion->"4.2 for Macintosh",
ScreenRectangle->{{24, 1152}, {0, 746}},
Evaluator->"Local",
WindowSize->{520, 724},
WindowMargins->{{26, Automatic}, {Automatic, 0}}
]

(*******************************************************************
Cached data follows.  If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of  the file.  The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1754, 51, 685, 16, 171, "Input"],

Cell[CellGroupData[{
Cell[2464, 71, 558, 11, 91, "Input"],
Cell[3025, 84, 141, 2, 27, "Output"]
}, Open  ]],

Cell[CellGroupData[{
Cell[3203, 91, 559, 11, 91, "Input"],
Cell[3765, 104, 141, 2, 27, "Output"]
}, Open  ]]
}
]
*)



(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)






On Saturday, January 4, 2003, at 07:54 AM, Andrzej Kozlowski wrote:

>
> Actually, I made a mistake in my message by copying the wrong code 
> from my notebook. The code:
>
> NMinimize[{Abs[eq], a == 4 && 0 <= b <= 9 &&
>       0 <= e <= 9 && 1 <= g <= 9 && 0 <= l <= 9 &&
>       0 <= m <= 9 && 0 <= s <= 9 && ss &&
>       Element[a | b | e |
>         g | l | m | s , Integers]}, Variables[eq]]
>
>
> also works  on my machine,  what does not work is:
>
> NMinimize[{Abs[eq], 0<=a<=9 && 1 <= b <= 9 &&
>       0 <= e <= 9 && 1 <= g <= 9 && 0 <= l <= 9 &&
>       0 <= m <= 9 && 0 <= s <= 9 && ss &&
>       Element[a | b | e |
>         g | l | m | s , Integers]}, Variables[eq]]
>
> However, the latter code seem to work on Allan's Microsoft Windows 
> version of 4.2, which isn't any newer than mine (?)
>
> On Saturday, January 4, 2003, at 04:11 AM, Daniel Lichtblau wrote:
>
>>
>>> [...] and then tried:
>>>
>>> NMinimize[{Abs[eq], a == 4 && 0 <= b <= 9 &&
>>>      0 <= e <= 9 && 1 <= g <= 9 && 0 <= l <= 9 &&
>>>      0 <= m <= 9 && 0 <= s <= 9 && ss &&
>>>      Element[a | b | e |
>>>        g | l | m | s , Integers]}, Variables[eq]]
>>>
>>> but disappointingly NMinimize was unable to find any solution that 
>>> gave
>>> 0 for the minimum of Abs.
>>
>> You need to upgrade (to our in-house development kernel).
>>
>> In[6]:= NMinimize[{Abs[eq], a == 4 && 0 <= b <= 9 &&
>>       0 <= e <= 9 && 1 <= g <= 9 && 0 <= l <= 9 &&
>>       0 <= m <= 9 && 0 <= s <= 9 && ss &&
>>       Element[a | b | e |
>>         g | l | m | s , Integers]}, Variables[eq]]
>>
>> Out[6]= {0., {a -> 4, b -> 7, e -> 3, g -> 1, l -> 5, m -> 9, s -> 8}}
>>
>>
>> Daniel
>>
>>
> Andrzej Kozlowski
> Yokohama, Japan
> http://www.mimuw.edu.pl/~akoz/
> http://platon.c.u-tokyo.ac.jp/andrzej/
>
>



  • Prev by Date: Re: Solving Alphametics with Mathematica
  • Next by Date: Re: Pasting tables into Excel
  • Previous by thread: Re: Solving Alphametics with Mathematica
  • Next by thread: Re: Solving Alphametics with Mathematica