CTM: Exercises of Chapter 1 (Exercise 1)
Posted by urban
The problem
A calculator. Section 1.1 uses the system as a calculator. Let us explore the possibilities:
(a) Calculate the exact value of 2100 without using any new functions Try to think of shortcuts to do it without having to type 2*2*2*...*2 with one hundred 2s. Hint: use variables to store intermediate results.
(b) Calculate the exact value of 100! without using any new functions. Are there any possible shortcuts in this case?
My solution
(a) As said in the hint, you have to store intermediate results:
declare
local V W X in
V={NewCell 2}
W = {NewCell 0}
X = {NewCell 0}
V := @V*@V % 2^2
V := @V*@V % 2^4
W := @V
V := @V*@V % 2^8
V := @V*@V % 2^16
V := @V*@V % 2^32
X := @V
V := @V*@V % 2^64
V := (@V*@W*@X) % 2^64 * 2^4 * 2^32 = 2^100
{Browse @V}
end
(b) Right now I can’t see a shortcut for computing 100!.

