Information Technology Reference
In-Depth Information
Figure 1.7.
A mystery procedure
Procedure PROCX:
You are given a sequence of digits
x
as input.
You will return a sequence of digits as output.
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
).
Set
side
to
2
×
b.
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
.