- Foundation
- About 13 min
- 5 practice questions
Rotation, swapping and arithmetic machines
Solve machines that rotate the line, swap elements from the two ends inward, or change numbers by a fixed amount at each step.
If something looks wrong, please tell us.
Not every machine sorts. Some rotate the line, some swap elements, and some change the numbers themselves. The method is the same: compare the input with Step I, state the rule in one sentence, and apply it to the new input one step at a time.
Three common rules
Machines that do not sort
- Rotation In each step the first element moves to the end of the line.
- Swapping inward Step I swaps the first and last; Step II the second and second-last, and so on.
- Arithmetic Each step adds or subtracts a fixed amount at certain positions.
- Rotation: in each step the first element moves to the end of the line.
- Swapping inward: Step I swaps the first and last elements; Step II swaps the second and second-last, and so on.
- Arithmetic: in each step a fixed amount is added to or subtracted from certain positions (for example, add 2 to the numbers in odd positions).
Worked examples
Example 1 (rotation). Input: 7 3 9 5. Rule: the first element moves to the end. Step I: 3 9 5 7. Step II: 9 5 7 3. Step III: 5 7 3 9. Step IV: 7 3 9 5. After 4 steps (the number of elements) the line is back to the input.
Rotation comes back to the input
- 7 3 9 5 The input, and Step IV.
- 3 9 5 7 Step I
- 9 5 7 3 Step II
- 5 7 3 9 Step III
Then back to step 1: 7 3 9 5
Example 2 (swapping inward). Input: pen cup bag ink lid fan. Step I swaps the first and last: fan cup bag ink lid pen. Step II swaps the second and second-last: fan lid bag ink cup pen. Step III swaps the third and third-last: fan lid ink bag cup pen. After 3 steps, every pair has been swapped and the machine stops. Notice that the final line is the input written in reverse order.
Example 3 (arithmetic). Input: 10 20 30 40. Rule: in each step, add 2 to the numbers in odd positions and subtract 1 from the numbers in even positions. Step I: 12 19 32 39. Step II: 14 18 34 38. Step III: 16 17 36 37.
For an arithmetic machine, track each position separately: odd positions follow one rule, even positions another.
Key takeaways
- Name the rule in one sentence from Step I.
- A rotation of n elements repeats after n steps.
- Track odd and even positions separately in arithmetic machines.
Check your understanding
-
1. Rule: in each step the first element moves to the end. Input: 3 8 5 1. What is Step II?
- 8 5 1 3
- 5 1 3 8
- 1 3 8 5
- 3 8 5 1
Show answer
Answer: B. Step I: 3 moves to the end, giving 8 5 1 3. Step II: 8 moves to the end, giving 5 1 3 8.
-
2. A rotation machine (first element to the end) works on 6 elements. After how many steps does the line first return to the input?
- 5
- 3
- 6
- 12
Show answer
Answer: C. A rotation of n elements first repeats after n steps, so 6 elements return after 6 steps.
-
3. Rule: Step I swaps the first and last elements, Step II swaps the second and second-last, and so on. Input: sun cup map key jar. What is Step II?
- jar key map cup sun
- jar cup map key sun
- sun key map cup jar
- jar key cup map sun
Show answer
Answer: A. Step I swaps sun and jar: jar cup map key sun. Step II swaps cup and key: jar key map cup sun.
-
4. Rule: in each step add 3 to the numbers in odd positions and subtract 2 from the numbers in even positions. Input: 5 20 15 30. What is Step II?
- 8 18 18 28
- 14 14 24 24
- 11 18 21 28
- 11 16 21 26
Show answer
Answer: D. Step I: 8 18 18 28. Step II: 8 + 3 = 11, 18 - 2 = 16, 18 + 3 = 21, 28 - 2 = 26, giving 11 16 21 26.
-
5. Same swapping-inward rule. Input: 1 2 3 4 5 6. What is the final line?
- 6 5 4 3 2 1
- 6 2 3 4 5 1
- 2 1 4 3 6 5
- 1 2 3 4 5 6
Show answer
Answer: A. Step I: 6 2 3 4 5 1. Step II: 6 5 3 4 2 1. Step III: 6 5 4 3 2 1. After every pair is swapped, the line is the input in reverse order.
Sign in to keep track of the lessons you finish.