Courses/CS 460/Fall 2005/Homework/Joey Leung/Nov 12
From CSWiki
< Courses | CS 460 | Fall 2005 | Homework | Joey Leung
Contents |
[edit] Pick two puzzles from FreePuzzles.com
[edit] Math002 - A to I are 1 to 9
AB X C ---- DE + FG ---- HI Every alphabet represents a different digit from 1 to 9 to make the calculation. What are they?
local
proc {Math002 Solution}
A B C D E F G H I
Vars = [A B C D E F G H I]
in
Solution = [A B C D E F G H I]
Vars ::: 1#9
(10*A + B) * C =: (D*10 + E)
(D*10 + E) + (F*10 + G) =: (H*10 + I)
{FD.distribute ff Vars}
{FD.distinct Vars}
end
in
{Browse {SearchAll Math002}}
end
[edit] Math003 - A strange 5 digit number
1ABCDE X 3 -------- ABCDE1 A five digit number is represented by ABCDE. If we add the number 1 in front of ABCDE, then times 3, the result number will be ABCDE appended by the number 1 (as shown in the figure). What is this five digit number?
local
proc {Math003 Solution}
A B C D E
Vars = [A B C D E]
in
Solution = [A B C D E]
Vars ::: 1#9
(100000 + A*10000 + B*1000 + C*100 + D*10 + E) * 3
=: (A*100000 + B*10000 + C*1000 + D*100 + E*10 + 1)
{FD.distribute ff Vars}
{FD.distinct Vars}
end
in
{Browse {SearchAll Math003}}
end
[edit] Math024 - Reverse the digit sequence by multuplying 7
ABCD X 7 ------- EDCBA What a magic number 7 is! It can reverse the digit sequence of a 4 digit number. A, B, C, D and E are distinct single digit numbers. What is the 4 digit number ABCD?
local
proc {Math024 Solution}
A B C D E
Vars = [A B C D E]
in
Solution = [A B C D E]
Vars ::: 1#9
(A*1000 + B*100 + C*10 + D) * 7
=: (E*10000 + D*1000 + C*100 + B*10 + A)
{FD.distribute ff Vars}
{FD.distinct Vars}
end
in
{Browse {SearchAll Math024}}
end
[edit] Math035 - From 1 to 9 to make a multiplication
**** X * ------- **** Fill in the boxes with 1, 2, 3, 4, 5, 6, 7, 8, and 9 to make the multiplication equation work.
local
proc {Math035 Solution}
A B C D E F G H I
Vars = [A B C D E F G H I]
in
Solution = [A B C D]#[E]#[ F G H I]
Vars ::: 1#9
(A*1000 + B*100 + C*10 + D) * E
=: (F*1000 + G*100 + H*10 + I)
{FD.distribute ff Vars}
{FD.distinct Vars}
end
in
{Browse {SearchAll Math035}}
end
[edit] Math065 - All prime numbers multiplication
Does not work, it returns a "nil".
***
X **
-------
****
****
-------
*****
Can you fill in only prime number digits in the boxes to make this equation possible?
It really means that you can only use number 2, 3, 5 nad 7 in the boxes.
local
proc {Math065 Solution}
A B C D E F G H I J K L M N O P Q R
Vars = [A B C D E F G H I J K L M N O P Q R]
in
Solution = [A B C]#[D E]#[F G H I]#[J K L M]#[N O P Q R]
Vars ::: {fun {$} choice 2 []3 []5 []7 end end}
%Vars ::: choice 2 []3 []5 []7 end
%Vars ::: 2
%Vars ::: 3
%Vars ::: 5
%Vars ::: 7
(A*100 + B*10 + C) * E =: (F*1000 + G*100 + H*10 + I)
(A*100 + B*10 + C) * (D*10) =: (J*10000 + K*1000 + L*100 + M*10)
(F*1000 + G*100 + H*10 + I) + (J*10000 + K*1000 + L*100 + M*10)
=: (N*10000 + O*1000 + P*100 + Q*10 + R)
{FD.distribute ff Vars}
end
in
{Browse {SearchAll Math065}}
end
[edit] DigitsToInt that uses FoldR

