Hi folks,

I'm working on the cryptarithmetic problem in Chapter 12 of CTM. It involves
generalizing the SEND + MORE = MONEY problem presented in the chapter.
Starting with the code in the chapter, I've made an incremental change
toward generalizing the code. However, it doesn't seem to be running all the
code. The three Browses in a row are for debugging, and are outputting the
correct intermediate results. However, they are only shown once, indicating
that NumberFor is only called once, even though it should be called three
times. Is it blocking somehow?

I have tried to run this through the debugger. It does not seem to want to
trace through the relevant calls. I have tried to set breakpoints, and
gotten an "error setting breakpoint". I have tried splitting up the line
with the three NumberFor calls into three separate statements, and putting
{Ozcar.breakpoint} calls before each one, but that doesn't stop the
debugger, either.

Any idea what is going wrong here?

declare

fun {SolveAll F}
   L={Solve F}
   proc {TouchAll L}
      if L==nil then skip else {TouchAll L.2} end
   end
in
   {TouchAll L}
   L
end

proc {SendMoreMoney ?Sol}
   S E N D M O R Y
   NumberFor

   fun {PowsOfTen Xs N}
      case Xs
      of nil then nil
      [] _|Xs then N|{PowsOfTen Xs N*10}
      end
   end
in
   Sol=sol('S':S 'E':E 'N':N 'D':D 'M':M 'O':O 'R':R 'Y':Y)
   Sol:::0#9
   {FD.distinct Sol}

   fun {NumberFor Word}
      AtomWord = {Map {Reverse Word} Char.toAtom}
   in
      {Browse atomWord(AtomWord)}
      {Browse mappedAtomWord({Map AtomWord fun {$ C} Sol.C end})}
      {Browse powsOfTen({PowsOfTen AtomWord 1})}
      {FD.sumC {Map AtomWord fun {$ C} Sol.C end} {PowsOfTen AtomWord 1}
'=:'}
   end

   S\=:0
   M\=:0
   {NumberFor "SEND"} + {NumberFor "MORE"} =: {NumberFor "MONEY"}
   %             1000*S + 100*E + 10*N + D
   %           + 1000*M + 100*O + 10*R + E
   %=: 10000*M + 1000*O + 100*N + 10*E + Y
   {FD.distribute ff Sol}
end

{Browse {SolveAll SendMoreMoney}}

Thanks,
Lyle
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to