Courses/CS 460/Fall 2005/Homework/Andre Liv/Nov 12

From CSWiki

Jump to: navigation, search

[edit] Homework 7

% Math021:   Sum of 4 Squares is a square of 85 
% A^2 + B^2 + C^2 + D^2 = 85^2
% This puzzle is derived from the Pythagorean Theorem. 
% A, B, C and D are either a single-digit or double-digit number

local
   proc {Math021 ?Sol}
      A B C D
   in
      Sol = [A B C D]
      Sol ::: 1#99
      {FD.distinct Sol}

      % constrain : If A < B < C < D, what are A, B, C, and D?
      thread
	 A < B = true
      end
      thread
	 B < C = true
      end
      thread
	 C < D = true
      end

      A * A + B * B + C * C + D * D =: 85*85
      {FD.distribute ff Sol}
   end
in
   {Browse {SearchAll Math021}}
end

% Math022: It was a saw 
% A 3 digit number WAS multiplied by a single digit 
% number the result number is the reverse of that 
% 3 digit number and prefixed with A. What is this 
% 3 digit number?

%   WAS
% *   S
% -----
% =ASAW


local
   proc {Math022 ?Sol}
      W A S
      Vars=[W A S]
   in
      Sol = [W A S]#[S]#[A S A W]
      Vars ::: 0#9   
      {FD.distinct Vars}
                     (100*W + 10*A + S)
         *                           S
         =:  1000*A + 100*S + 10*A + W
      {FD.distribute ff Vars}
   end
in
   {Browse {SearchAll Math022}}
end
% Math025:   The Cubes of 3 consecutive numbers 
% Four positive consecutive numbers A, B, C, 
% and D are arranged where the sum of the cubes 
% of the first 3 numbers (A, B, C) is the cube 
% of the last number (D). What are these numbers?


local
   proc {Math021 ?Sol}
      A B C D
   in
      Sol = [A B C D]
      Sol ::: 1#99
      {FD.distinct Sol}

      % constrain to be consecutive
      thread
	 B - A =: 1
      end
      thread
	 C - B =: 1
      end
      thread
	 D - C =: 1
      end

      A * A * A + B * B * B + C * C * C  =: D * D * D
      {FD.distribute ff Sol}
   end
in
   {Browse {SearchAll Math021}}
end