Courses/CS 460/Fall 2005/Homework/Francisco Velazquez/HW6/Nov5

From CSWiki

Jump to: navigation, search
</td>

[edit] LET THERE BE LIGHT

local
  proc {LTBL Solution}
     L E T H R B I G 
     Vars = [L E T H R B I G ]
  in
     Solution = [L E T ]#[T H E R E]#[B E]#[L I G H T]
     Vars ::: 0#9                                      
     {FD.distinct Vars}   
     %Choose an answer                             
     B \=: 1                                        
           
                         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 LTBL}}
end

[edit] Rotating Digits

local %Browse through a list of lists

fun {Rotate Xs Zs Ys }

  A1 A2 A3 A4 A5 A6 B1 B2 B3 B4 B5 B6  G J in
  case Xs of
     nil then Ys
  [] X|Xr then
     Zs=[B1 B2 B3 B4 B5 B6]
     X=[A1 A2 A3 A4 A5 A6]
     %rotate the first part only of the previous result using string conversion
     %G={String.toInt {VirtualString.toString "1"#B2#B3#B4#B5#B6#B1}}
     %J={String.toInt {VirtualString.toString "1"#A1#A2#A3#A4#A5#A6}}
     
     %rotate the first part only of the previous result
     G=B2*100000+B3*10000+B4*1000+B5*100+B6*10+B1
     J=A1*100000+A2*10000+A3*1000+A4*100+A5*10+A6
     %compare the rotated part
     if(G==J)then {Rotate Xr X {Append  Ys [X]}}
             else    {Rotate Xr Zs Ys}
     end
   end  

end

proc {LTBL Solution}

     A B C D E F 
  Vars = [A B C D E F]
  

in

  Vars ::: 0#9
  {FD.distinct Vars}
  %Do some variations
 choice
     
    {Multx [A B C D E F] 1 [A B C D E F]}
      Solution=[A B C D E F]      
    []
    {Multx [A B C D E F] 3 [B C D E F A]}
      Solution=[B C D E F A]
     []
     {Multx [A B C D E F] 2 [C D E F A B]}
     Solution=[C D E F A B]
     []
      {Multx [A B C D E F] 6 [D E F A B C]}
      Solution=[D E F A B C]
      []
     {Multx [A B C D E F] 4 [E F A B C D]}
     Solution=[E F A B C D]
     []
     {Multx [A B C D E F] 5 [F A B C D E]}
     Solution=[F A B C D E]
   end
  
   {FD.distribute ff Vars}
   
  end
  
  

proc {Multx L1 X L2 }

     A B C D E F G H I J K L
  in
     {Length L1} =: 6 
     {Length L2} =: 6
     L1 = [A B C D E F]
     L2 = [G H I J K L]
     (A*100000+B*10000+C*1000+D*100+E*10+F) * X =: (G*100000+H*10000+I*1000+J*100+K*10+L)
      

end Answer Cs Ds in

  Answer= {SearchAll LTBL}
  Answer=Cs|Ds
  {Browse {Rotate Ds Cs [Cs]}}

end



[edit] Divisible

local

 proc {Mods Solution}
  A B C D E F G H I %O
  Vars = [A B C D E F G H I]   

in

  Solution=[A B C D E F G H I]
  Vars ::: 0#9
    {FD.distinct Vars}
  %Distribute numbers using Kelly's method
  A =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  B =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  C =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  D =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  E =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  F =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  G =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  H =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
  I =:{fun{$}choice 0[] 1[] 2[] 3[] 4[] 5[] 6[] 7[] 8[] 9 end end}
   
  %Do some rotating and comparing
  choice      
     {Multx [A B C D E F G H I] Solution}
     []
     {Multx [B C D E F G H I A] Solution}
     []
     {Multx [C D E F G H I A B] Solution}
     []
     {Multx [D E F G H I A B C] Solution}
     []
     {Multx [E F G H I A B C D] Solution}
     []
     {Multx [F G H I A B C D E ] Solution}
     []
     {Multx [G H I A B C D E F] Solution}
     []
     {Multx [H I A B C D E F G] Solution}
     []
     {Multx [I A B C D E F G H] Solution}       
   end
     {FD.distribute ff Vars}

end

proc {Multx L1 ?L2}

  A B C D E F G H I   O
  in
  L1 = [A B C D E F G H I]
  I=:0
  A\=:0
  %H>=:4
  %H\=:5
  %H\=:7
  %H=<:8
  %create a cell to hold the computation
  O={NewCell (100000000*A+10000000*B+1000000*C+100000*D+10000*E+1000*F+100*G+10*H+I)}  
 (@O mod 2) =: 0
 (@O mod 3) =: 0
 (@O mod 4) =: 0
 (@O mod 5) =: 0
 (@O mod 6) =: 0
 (@O mod 7) =: 0
 (@O mod 8) =: 0
 (@O mod 9) =: 0
 L2=@O   

end Lis in

   Lis={SearchAll Mods}
  {Browse Lis}
  {Browse {Length Lis}}
  

end