Re: Solving Alphametics with Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg38679] Re: Solving Alphametics with Mathematica
- From: David Jameson <nospam at nospam.digiportal.com>
- Date: Sat, 4 Jan 2003 07:26:48 -0500 (EST)
- References: <auuaku$pjh$1@smc.vnet.net> <av36pf$g00$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
OK - I think I mostly understand this algorithm. A couple of questions. *) I'd like to be able to generalise it so that it's not limited to this particular sum (base+ball=games). Can the '5' in the first line be changed so that it is calculated from the argument list rather than being hard-coded? *) Same for the '7' in the MatchQ function *) Same for the '5' in the Table function *) As well as the result, how can we display the value of each character, which is in fact the real goal? Finally, I note that a little 'manual' work was done to determine which characters are in the operands but not in the result. It would be nice if this could also be 'calculated' so that one could simply feed this program the string base+ball=games and have the result figured out. Thanks, David -- ____________________________ Dr. David H. Jameson Founder and CTO DigiPortal Software Inc. There's too much spam out there. Protect yourself with ChoiceMail http://www.digiportal.com "Orestis Vantzos" <atelesforos at hotmail.com> wrote in message news:av36pf$g00$1 at smc.vnet.net... > A fairly literal implementation of the problem: > > criterion[lst:{b_,a_,s_,e_,l_}]/;Length[Union[lst]]==5:= > Module[{base=FromDigits[{b,a,s,e}],ball=FromDigits[{b,a,l,l}],games}, > games=IntegerDigits[base+ball]; > MatchQ[games,{g_,a,m_,e,s}/;Length[Union[{g,m},lst]]==7]] > > criterion[_]=False; > > Table[If[criterion@IntegerDigits[n, 10, 5], Print[n]], {n, 0, 10^5 - 1}]; > > 74835 > > Which means that B=7,A=4,S=8,E=3,L=5, > so that: > BASE+BALL=GAMES > is > 7483+7455=14938 > > Orestis > David Jameson <nospam at nospam.digiportal.com> wrote in message news:<auuaku$pjh$1 at smc.vnet.net>... > > Anyone know how to use Mathematic to solve Alphametics puzzles? > > For example, the sum > > > > B A S E > > + B A L L > > ------------------- > > G A M E S > > > > has only one solution in base 10. I've tried several ways of represent this > > "sum" in Mathematica but have not been able to get it to solve it. > > > > There are lots of other examples of these puzzles at > > http://www.creativepuzzels.nl/spel/speel1/frameng.htm > > if anyone is interested. > > > > Cheers, > > David Jameson >