From CSULA CS Wiki
< Courses‎ | CS 460‎ | Fall 2005‎ | Homework‎ | Andre Liv
Jump to: navigation, search

Homework 6

% LET + THERE + BE = LIGHT
local
   proc {Light Solution}
      G E T H L R I B
      Vars = [G E T H L R I B]
   in
      Solution = [L E T]#[T H E R E]#[B E]#[L I G H T]
      Vars ::: 0#9
      {FD.distinct Vars}
      L \=: 0
      T \=: 0
      B \=: 0
                            100*L + 10*E + T
      +  10000*T + 1000*H + 100*E + 10*R + E
      +                             10*B + E
      =: 10000*L + 1000*I + 100*G + 10*H + T
      {FD.distribute ff Vars}

   end
in
   {Browse {SearchAll Light}}
   {ExploreAll Light}
end
% Rotating digits
local
   fun {ConvertToInt List}
      {FoldL List fun {$ K L} {FD.plus {FD.times K 10} L} end 0}
   end
   
   proc {Digits Sol} A B C D E F
   in
      Sol = [A B C D E F]
      Sol ::: 1#9
      {FD.distinct Sol}
      {Mult Sol 1 [A B C D E F]}
      {Mult Sol 2 [C D E F A B]}
      {Mult Sol 3 [B C D E F A]}
      {Mult Sol 6 [D E F A B C]}
      {Mult Sol 4 [E F A B C D]}
      {Mult Sol 5 [F A B C D E]}
      
      {FD.distribute ff Sol}
   end
   
   proc {Mult L1 X L2}
      {ConvertToInt L1} * X =: {ConvertToInt L2}
   end
in
   {Browse {SearchAll Digits}}
   {ExploreAll Digits}
end