Courses/CS 460/Fall 2005/Homework/Kelly Breed/Nov 12

From CSWiki

Jump to: navigation, search

My main homework page

Contents

[edit] HW 7

[edit] DigitsToInt using FoldR

local
   fun {DigitsToInt L}
      A in
      A#_ = {FoldR L fun {$ N S#P} ({Pow 10 P}*N+S)#P+1 end 0#0}
      A
   end
in
   {Browse {DigitsToInt [1 2 3 4 5]}}
end

[edit] FLY+FOR+YOUR=LIFE

The original code contained a duplicate variable which prohibited it from finding an answer with the variables constrained by FD.distinct.

Presented in class Nov. 12

local
   proc {Fly Solution}
      fun {DigitsToInt L}
	 A in
	 A#_ = {FoldR L fun {$ N S#P} ({FD.plus {FD.times {FD.power 10 P} N} S})#P+1 end 0#0}
	 A
      end
      F L Y O U R I E
      Vars = [F L Y O U R I E]
   in
      Solution = [[Y O U R][L I F E]]
      Vars ::: 0#9
      {FD.distinct Vars}
      F \=: 0
      Y \=: 0
      L \=: 0
      O =: 0
      I =: 1
      {FD.plus {FD.plus {DigitsToInt [F L Y]} {DigitsToInt [F O R]}} {DigitsToInt [Y O U R]}} =: {DigitsToInt [L I F E]}
      {FD.distribute ff Vars}
   end
   R
in
   R = {SearchAll Fly}
   {Browse {Length R}}
   {Browse R}
end

My user page.</pre>