Exercise · Volume 1 · 2.1-1
Exercise 2.1-1
not stated yet in Lean solution written
| Rating | 04 |
|---|---|
| Kind | K3, find a value: compute a number, a set or a closed form from the written solution |
| Section | Section 2.1 of Volume 1 |
The task
Read two values from the picture of the card pile: the suit of the second card, and the link in the third card.
The exact wording is in your copy of the book.
Hints
Open one hint at a time. Try the exercise again after each.
Hint 1
Start from the picture (3). Each box is a node, and TOP points to the first node.
Hint 2
NEXT(X) is the link stored in the node that X points to. Apply it from the inside out.
Solution
Show the solution
TOP points to the first node, which is at address . By (2), the NEXT field of this node holds , so NEXT(TOP) = 386. The node at has SUIT = 4, which stands for spades. So (a) SUIT(NEXT(TOP)) = 4.
For (b), NEXT(TOP) = 386 and NEXT(386) = 100. The node at is the bottom card, and its NEXT field is the null link. So NEXT(NEXT(NEXT(TOP))) = \Lambda.
Check
Count the cards: there are three nodes, so a chain of three NEXT steps from TOP must leave the pile. The chain is .
Remarks
The answer to (b) is the null link and not a node, so no field can be taken of it. An algorithm that follows NEXT must test for before it goes on, as the counting algorithm of the section does.
This solution is drafted, and a person has not reviewed it yet. The source.
In Lean
not stated yet The exercise is not stated in Lean yet.
The status is computed from the Lean build. The node of the map.
Something is wrong? Report it.