Exercise · Volume 1 · 2.2.1-2
Exercise 2.2.1-2
not stated yet in Lean solution written
| Rating | 15 |
|---|---|
| Kind | K2, decide: say whether a claim holds from the written solution |
| Section | Section 2.2.1 of Volume 1 |
The task
Decide whether six cars in the order can leave a stack in the order , and in the order . Show a way to do it when it is possible.
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
Write each move as S (input to stack) or X (stack to output). The cars enter in the order .
Hint 2
For the second order, look at the moment when car leaves. Which of the cars and are then in the stack, and in which order?
Solution
Show the solution
First order, . The sequence of moves SSSXXSSXSXXX works. The table shows the stack from bottom to top after each move.
| move | stack | output |
|---|---|---|
| S | 1 | |
| S | 1 2 | |
| S | 1 2 3 | |
| X | 1 2 | 3 |
| X | 1 | 3 2 |
| S | 1 4 | 3 2 |
| S | 1 4 5 | 3 2 |
| X | 1 4 | 3 2 5 |
| S | 1 4 6 | 3 2 5 |
| X | 1 4 | 3 2 5 6 |
| X | 1 | 3 2 5 6 4 |
| X | 3 2 5 6 4 1 |
Second order, . It is impossible. Car leaves first, and then car . The cars enter in increasing order, so cars and enter the stack before car does. They leave after car , because the output has before both. So at the time when car leaves, the stack holds and , with above because entered later. A stack gives up before . The wanted output has before . This is a contradiction.
Check
I generated all permutations of that a stack gives, by a search over all move sequences. There are of them. The order is among them, and the order is not.
Remarks
The argument for the second order is a special case of the rule of Exercise 2.2.1-5. The three cars are in the forbidden relative order.
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.