- Practice
- About 14 min
- 5 practice questions
Swap, position and value machines: rules that change items instead of ordering them
Follow machines that swap items from the two ends, change numbers according to their place in the line, or change numbers according to their value, and avoid the usual traps.
If something looks wrong, please tell us.
Not every machine sorts. Some swap items between the two ends of the line, some add or subtract according to the place in the line, and some change each number according to whether it is odd or even. The order of the items may stay the same while their values change. The key skill is to read the rule precisely and decide whether it works on positions or on values.
Machine 1: swapping from the two ends
The rule is: in Step I the first and last items swap; in Step II the second and the second-last items swap; and so on. After half the items have been swapped, the line is the reverse of the input and the machine stops. With six items there are 3 steps; with seven items there are also 3 steps, because the middle item has nothing to swap with.
Example 1. Input: 7 12 5 9 3 8.
| Step | Arrangement |
|---|---|
| Input | 7 12 5 9 3 8 |
| I | 8 12 5 9 3 7 |
| II | 8 3 5 9 12 7 |
| III | 8 3 9 5 12 7 |
Step III gives 8 3 9 5 12 7, which is the input read backwards. The machine takes 3 steps.
Example 2. Input: P L A N E T. Step I: T L A N E P. Step II: T E A N L P. Step III: T E N A L P. The line is the reverse of PLANET, as expected.
Machine 2: rules that depend on the position
The rule is: in every step, 4 is added to the number in each odd place (first, third, ...) and 3 is subtracted from the number in each even place (second, fourth, ...). The place is what matters, not the number.
Example 3. Input: 10 20 30 40.
| Step | Arrangement |
|---|---|
| Input | 10 20 30 40 |
| I | 14 17 34 37 |
| II | 18 14 38 34 |
| III | 22 11 42 31 |
In Step II, the first number 14 becomes 18 and the second number 17 becomes 14. The rule is applied to the previous step, not to the input. In Step III, the second number 14 becomes 11 and the fourth number 34 becomes 31.
Machine 3: rules that depend on the value
The rule is: in every step, an even number is halved and an odd number is increased by 5. The value of the number decides what happens, wherever it stands in the line.
Example 4. Input: 14 9 20 7.
| Step | Arrangement |
|---|---|
| Input | 14 9 20 7 |
| I | 7 14 10 12 |
| II | 12 7 5 6 |
| III | 6 12 10 3 |
In Step I, 14 is even and becomes 7, 9 is odd and becomes 14, 20 becomes 10 and 7 becomes 12. In Step II the rule is applied again to the new numbers: 7 becomes 12, 14 becomes 7, 10 becomes 5 and 12 becomes 6.
Ask two questions about every rule: does it act on places or on values, and is it applied to the previous step or to the input?
Traps
- Applying the rule to the input at every step instead of to the line you have just written.
- Treating a place-based rule as a value-based one, or the other way round.
- Stopping a swap machine too early or too late: it ends when the swaps meet in the middle.
- Skipping a step in which a number happens to stay the same.
Key takeaways. For a swap machine, the number of steps is half the number of items, rounded down. For place rules, count places from the left each time. For value rules, test odd or even afresh at each step. Always build on the previous step.
Check your understanding
-
1. Rule: Step I swaps the first and last items, Step II swaps the second and second-last, and so on. Input: 7 12 5 9 3 8. What is Step II?
- 8 3 5 9 12 7
- 8 12 5 9 3 7
- 8 3 9 5 12 7
- 3 8 5 9 12 7
Show answer
Answer: A. Step I: 8 12 5 9 3 7. Step II swaps 12 and 3, giving 8 3 5 9 12 7.
-
2. A machine swaps the first and last items in Step I, the second and second-last in Step II, and so on. How many steps does a line of 7 items need to be completely reversed?
- 2
- 3
- 4
- 7
Show answer
Answer: B. Step 1 swaps places 1 and 7, step 2 swaps 2 and 6, step 3 swaps 3 and 5. The middle item, place 4, stays. So 3 steps.
-
3. Rule: in every step, add 4 to the numbers in odd places and subtract 3 from the numbers in even places. Input: 10 20 30 40. What is Step III?
- 22 17 42 37
- 18 14 38 34
- 22 11 42 31
- 22 14 42 34
Show answer
Answer: C. Step I: 14 17 34 37. Step II: 18 14 38 34. Step III: 22 11 42 31.
-
4. Rule: in every step, an even number is halved and an odd number is increased by 5. Input: 14 9 20 7. What is Step II?
- 7 14 10 12
- 6 12 10 3
- 12 7 10 6
- 12 7 5 6
Show answer
Answer: D. Step I: 7 14 10 12. Step II: 7 is odd, so 12; 14 is even, so 7; 10 is even, so 5; 12 is even, so 6. The line is 12 7 5 6.
-
5. Rule: in every step, an even number is halved and an odd number is increased by 5. Input: 14 9 20 7. What is Step III?
- 6 12 10 3
- 12 7 5 6
- 6 12 5 3
- 7 14 10 12
Show answer
Answer: A. Apply the rule to Step II (12 7 5 6): 12 becomes 6, 7 becomes 12, 5 becomes 10, 6 becomes 3. The line is 6 12 10 3.
Sign in to keep track of the lessons you finish.