Question: This Example comes from Levesque's Thinking as Computation textbook. The ^ sign is concatination. We are supposed to figure out what the procedure does: -

This Example comes from Levesque's Thinking as Computation textbook. The ^ sign is concatination. We are supposed to figure out what the procedure does:

-

You are given a sequence of digits x as input.

You will return a sequence of digits as output.

Hint: Trace its behavior when the input is 137641.

1) Group the digits in x into pairs starting from the right. (If x has an odd number of digits, the leftmost group will only have a single digit in it.)

2)Start with u, v, bot, top, and side all having an initial value of 0.

3)Then, working your way from left to right on the groups in x, repeat the following:

a)Set bot to (bot-u) ^(the next group from x).

b)Set side to 2 * top.

c)Set v to the largest single digit such that v * (side^v) <= bot.

d)Set u to v * (side^v).

e)Set top to top^v.

4)The answer to return is the final value of top.

-

I've traced through it with the numbers myself, with the final result of top=173, but the numbers don't seem right and i don't see a pattern.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!