ExamSaathi learning library · Government exams · IBPS and SBI PO and clerk reasoning (main examinations); sections named in the 2026 notices, which give no topic list · General intelligence and reasoning

Machine input-output: finding the rule behind each rearrangement step

Find the rule a machine follows as it rearranges a line of words and numbers one step at a time: compare the input with steps I and II, check the rule on every step, write each later step in full and spot the last step, for shift, swap and changing machines.

Status: original pilot lesson. Teacher review is pending. It is not a complete course or official exam material.

You will learn to

Before you start

The 2026 IBPS PO/MT-XVI notice lists Reasoning as one of the tests of the main examination and names no topics within it.

In a machine input-output question, a machine takes an input line of words and numbers, such as sun 47 rain 12 cloud 85 wind 30, and rearranges it one step at a time. It repeats one fixed rule until a final step, and each step works on the line that the step before it left. You are shown the input and some steps; you must find the rule and use it.

What to know first:

1. Each word or number in the line is one element. Count the elements before you begin.

2. Number the places from the left. A place counted from the right equals total - place from the left + 1.

3. Compare two-digit numbers by their tens digits first, then by their units digits.

Related lessons on this site, one line each:

1. The ranking and order lesson counts places from either end of a row and the people standing between two persons.

2. The number arrangement lesson changes and reorders the digits inside each number, whereas here whole elements move.

3. The alphabet tests lesson puts words in dictionary order: compare them letter by letter, and the first letter that differs decides.

The shift pattern: one element moves, the rest keep their order

In the shift pattern, each step takes one element out of the line and puts it at one end, beside the elements moved in earlier steps. Every other element closes the gap and keeps its old order. So a settled part grows at one end while the rest wait in their input order.

To read a step, write it under the line before it and find the one element that jumped. Then ask: which element moved, a word or a number? To which end did it go? Why that one: first or last in dictionary order, longest or shortest word, smallest or largest number? Does a word take turns with a number?

Example. Input: 64 roti 18 chai 31 mela

Step I: chai 64 roti 18 31 mela

Step II: chai 18 64 roti 31 mela

Step III: chai 18 mela 64 roti 31

Step IV: chai 18 mela 31 64 roti

Step V: chai 18 mela 31 roti 64

In step I, chai jumped to the left end, and 64 roti 18 31 mela kept their order. In step II, 18, the smallest number, joined just right of chai. Step III brings mela, not roti, the last word, and step IV brings 31, not 64, the largest number. All three words have 4 letters, so words go in dictionary order, taking turns with numbers from the smallest. After step V only 64 is left, already last, so the machine stops. Also see where the step II element lands: next to the step I element, as here, or at the very end, pushing the step I element one place in.

Finding the rule, checking it and answering

Work through every question in this order.

1. Compare the input with step I, then step I with step II. Write the guessed rule in words: what moves, to which end, in what order and where it lands.

2. Check the guess on every step given. Predict each step from the line above it, element by element, before you look. If one element differs, the guess is wrong, so go back. This is a dry run: tracing a rule on a real input shows up a wrong step early.

3. Write each later step in full, one line per step. Never jump from step II to step V, since each step works on the line the step before it left.

4. Read the answer from the stated step. A place from the right is total - place from the left + 1, and the number of elements between two elements is the difference of their places minus 1.

5. Spot the last step. The machine repeats its rule until the line is in final order and stops at the first step that gives that order. When each element joins next to those moved earlier, the last one falls into place along with the one before it, so n elements need at most n - 1 steps. There can be fewer: if the unmoved elements already stand in final order, the machine stops early, and an element already in its place needs no step. When each element goes to the very end instead, pushing the others in, the last element needs a step of its own too.

Swap patterns and steps that change the elements

Swap pattern. If, between two steps, exactly two elements have new places and every other element stands where it was, the machine swaps. A move by one place looks the same in both patterns, so judge from a step where an element travels further. Find the reason as for a shift: the element due next is brought to its place, and the element that stood there takes the place it left. The rest do not close up, so the unsettled elements lose their input order. A swap can settle two elements at once, when the partner happens to land in its own final place; that element needs no step later. So n elements need at most n - 1 swaps, and sometimes fewer.

Changing machines. If an element vanishes and a new one appears, the machine changes elements. Compare the old and new values and test these changes: add or subtract a fixed number (18 becomes 13 when 5 is taken away), replace a number by its digit sum (47 becomes 4 + 7 = 11), reverse a word (ravi becomes ivar) or move each letter one place forward in the alphabet (tea becomes ufb). Check the change on a second element before you trust it. In this lesson's examples, the order follows the original elements and every element is changed once, so even the last one needs its own step. In a new question, let the given steps decide whether the order uses the original or the changed values, which elements change, and when nothing is left to do.

Common mistakes

1. Guessing the rule from one move. A single move fits several rules: the first word in dictionary order also starts the rule that takes the first and last words in turn. Check at least two moves of each kind, and every later step given.

2. Disturbing the unmoved elements in a shift. They keep their order; copy them across exactly.

3. Closing the gap after a swap. The partner simply takes the place the moved element left, and nothing else moves.

4. Wrong dictionary order. Compare letter by letter: bajra comes before bihu because a comes before i in the second place.

5. Putting the moved element at the very end when it should sit next to the elements moved earlier, or the other way round. Step II shows which.

6. Skipping steps. Each step needs the full line of the step before.

7. Counting steps by formula. Eight elements may need fewer than 7 steps, and when every element must be changed, one per step, each needs a step of its own.

8. Ordering by the wrong value. Check in the given steps whether the order follows the original or the changed elements. In this lesson's examples it follows the originals: 63 takes its turn as 63 and only then becomes 58.

9. Counting a place from the wrong end, or forgetting to take away 1 when counting the elements between two others.

A routine for machine input-output questions

1. Count the elements, and note how many are words and how many are numbers.

2. Compare the input with step I and step I with step II: which element moved or changed, to which end, and why that one.

3. Name the pattern: shift (one element moves and the rest keep their order), swap (two elements change places) or change (an element gets a new value).

4. Write the rule in one sentence, with the order and where each element lands.

5. Dry run: predict each given step from the one before it and compare element by element.

6. Write every later step in full, one line per step.

7. Stop at the first line where the rule has nothing left to do: the line is in final order and every element that the rule changes has been changed.

8. Read the answer from the stated step, counting places from the stated end.

9. Check that your line has as many elements as the input, with none lost or repeated.

Worked examples

  1. A machine rearranges a line of town names and numbers one step at a time. Input: 39 kochi 74 nagpur 86 ooty 51 lucknow. Step I: lucknow 39 kochi 74 nagpur 86 ooty 51. Step II: lucknow 86 39 kochi 74 nagpur ooty 51. Step III: lucknow 86 nagpur 39 kochi 74 ooty 51. Step IV: lucknow 86 nagpur 74 39 kochi ooty 51. Find the rule, write every remaining step and say how many steps the machine needs.

    1. Input to step I: only lucknow has moved, from the right end to the left end, and the other seven still read 39 kochi 74 nagpur 86 ooty 51. So this is a shift. In dictionary order the words run kochi, lucknow, nagpur, ooty, so lucknow is neither first nor last, but with 7 letters it is the longest word.
    2. Step I to step II: 86, the largest number, has moved and sits just right of lucknow. Guess: the longest word left and the largest number left take turns, each placed just after the elements moved before.
    3. Check on steps III and IV. Of nagpur (6 letters), kochi (5) and ooty (4), the longest is nagpur, and step III moves nagpur, not ooty, the shortest. Step IV moves 74, the largest number left, not 39, the smallest, so the numbers run straight down. In both steps the unmoved elements keep their old order. The guess holds.
    4. Write the rest in full. Step V moves kochi: lucknow 86 nagpur 74 kochi 39 ooty 51. Step VI moves 51: lucknow 86 nagpur 74 kochi 51 39 ooty. Step VII moves ooty: lucknow 86 nagpur 74 kochi 51 ooty 39.
    5. After step VII only 39, the smallest number, is left, and it already stands last, which is its place. So step VII is the last step: 8 elements need 8 - 1 = 7 steps, because the last element falls into place along with the one before it.

    Answer: Rule: the longest word and the largest number take turns, each placed just after those already moved. The last step is step VII: lucknow 86 nagpur 74 kochi 51 ooty 39, so the machine needs 7 steps.

  2. A machine rearranges a line of festival names and numbers one step at a time. Input: 51 onam bihu teej holi 25 48. Step I: bihu onam 51 teej holi 25 48. Step II: bihu 25 51 teej holi onam 48. Step III: bihu 25 holi teej 51 onam 48. Step IV: bihu 25 holi 48 51 onam teej. Find the rule and write the remaining steps. Which element is third from the right in step V, and how many steps does the machine need?

    1. Input to step I: bihu and 51 have changed places, and every other element stands exactly where it was. So this is a swap. bihu comes first in dictionary order (bihu, holi, onam, teej) and now stands first; all four words have 4 letters, so length cannot be the rule.
    2. Step II swaps 25 and onam, putting 25, the smallest number, second. Step III swaps holi and 51, putting holi, the next word, third. Step IV swaps 48 and teej, putting 48, not 51, fourth. Rule: words in dictionary order and numbers from the smallest take turns, and each is swapped into the next place from the left.
    3. Step IV also sent teej to place 7, which happens to be its final place, since teej is last in dictionary order. So teej will need no step of its own.
    4. Step V: onam, the next word, swaps with 51 in place 5. Result: bihu 25 holi 48 onam 51 teej. Now 51 is in place 6 and teej in place 7, so the whole line is in final order and the machine stops. In this line onam is third from the right.
    5. Count: 5 steps. Two elements, teej in step IV and 51 in step V, reached their final places as partners in other elements' swaps, so 7 elements needed only 7 - 2 = 5 steps, not 7 - 1 = 6.

    Answer: onam is third from the right in step V. The last step is step V: bihu 25 holi 48 onam 51 teej, so the machine needs 5 steps.

  3. A machine changes and moves a line of breakfast items and numbers one step at a time. Input: vada 63 idli 18 dosa 45 puri 72. Step I: vada 63 idli 18 45 puri 72 asod. Step II: vada 63 idli 45 puri 72 asod 13. Step III: vada 63 45 puri 72 asod 13 ildi. Step IV: vada 63 puri 72 asod 13 ildi 40. Find the rule, write the remaining steps and say which step is the last.

    1. Input to step I: dosa has gone and a new word, asod, stands at the right end. Read backwards, asod is dosa, the word first in dictionary order (dosa, idli, puri, vada). So the machine reverses a word and sends it to the right end.
    2. Step II: 18, the smallest number, has gone and 13 stands at the right end, so 18 - 5 = 13. Step III sends idli as ildi, and step IV sends 45 as 40, since 45 - 5 = 40. Both changes hold on a second element.
    3. Each new element takes the very end, so the earlier ones slide one place left, and the unchanged elements keep their order. Rule: by turns, the next word in dictionary order is reversed and the smallest number left loses 5, and each goes to the right end.
    4. Step V: vada 63 72 asod 13 ildi 40 irup (puri reversed). Step VI: vada 72 asod 13 ildi 40 irup 58 (63 - 5). Step VII: 72 asod 13 ildi 40 irup 58 adav (vada reversed).
    5. After step VII, 72 is still unchanged, so the machine is not done. Step VIII: asod 13 ildi 40 irup 58 adav 67 (72 - 5). Now every element has been changed once. With 4 words and 4 numbers, each needing its own step, the machine needs 4 + 4 = 8 steps, not 7.

    Answer: Rule: by turns, the next word in dictionary order is reversed and the smallest number left loses 5, and each goes to the right end. The last step is step VIII: asod 13 ildi 40 irup 58 adav 67, so the machine needs 8 steps.

Practice checks

  1. A machine rearranges a line of names and numbers one step at a time. Input: salma rohit 12 84 arjun 49 57 kiran. Step I: 84 salma rohit 12 arjun 49 57 kiran. Step II: 84 arjun salma rohit 12 49 57 kiran. Step III: 84 arjun 57 salma rohit 12 49 kiran. Step IV: 84 arjun 57 kiran salma rohit 12 49. Which of these is step VI?
  2. A machine rearranges a line of foodgrains and numbers one step at a time. Input: 58 wheat 41 bajra 27 86 rajma jowar. Step I: bajra 58 wheat 41 27 86 rajma jowar. Step II: bajra 27 58 wheat 41 86 rajma jowar. Step III: bajra 27 jowar 58 wheat 41 86 rajma. Step IV: bajra 27 jowar 41 58 wheat 86 rajma. The machine keeps to the same rule until the arrangement is complete. How many steps does it need in all?
  3. A machine rearranges a line of words and numbers one step at a time. Input: lotus mango 46 cobra 93 15 tiger 72. Step I: 93 mango 46 cobra lotus 15 tiger 72. Step II: 93 cobra 46 mango lotus 15 tiger 72. Step III: 93 cobra 72 mango lotus 15 tiger 46. Step IV: 93 cobra 72 lotus mango 15 tiger 46. Which element is second from the right end in step V?
  4. A machine changes and moves a line of drinks, sweets and numbers one step at a time. Input: 39 lassi 86 78 barfi kulfi. Step I: cbsgj 39 lassi 86 78 kulfi. Step II: cbsgj 14 39 lassi 78 kulfi. Step III: cbsgj 14 lvmgj 39 lassi 78. Step IV: cbsgj 14 lvmgj 15 39 lassi. Which of these is the last step?
  5. A machine rearranges a line of fruits and numbers one step at a time. Input: 38 mulberry papaya jamun 64 15 91 guava. Step I: 38 mulberry papaya jamun 64 15 guava 91. Step II: 38 mulberry jamun 64 15 guava papaya 91. Step III: 38 mulberry jamun 15 guava 64 papaya 91. Step IV: 38 jamun 15 guava mulberry 64 papaya 91. In step V, how many elements stand between jamun and papaya?

Sources checked