Practice30Create account

A word-and-number arrangement machine, when given an input line of words and numbers, rearranges it in steps. In each step the machine attends to the prime numbers first: it takes the smallest prime that has not already been shifted and places it at the extreme left end of the line. Once no prime is left unshifted, it takes the smallest of the remaining numbers and places it at the extreme left end in the same way. Every other element keeps its relative position, and the machine stops once every number has been shifted.
Input: sonnet 45 brine 29 crest 62 dwell 71.
At which step of the above arrangement does the line "62 45 71 29 sonnet brine crest dwell" appear?

Competition practiceInput-Output
  • AStep 2
  • BStep 1
  • CStep 4
  • DStep 3

Step-by-Step Solution

Primes: 29 and 71. Not prime: 45 and 62. Order of shifting: 29, 71, then 45, then 62. Step 1: 29 sonnet 45 brine crest 62 dwell 71. Step 2: 71 29 sonnet 45 brine crest 62 dwell. Step 3: 45 71 29 sonnet brine crest 62 dwell. Step 4: 62 45 71 29 sonnet brine crest dwell — the line asked about, and the last one, since all four numbers have now been shifted. A useful check: no number is left in mid-line, which can only be true at the final step.
Answer: C) Step 4

Master this topic in 30 minutes a day.

Don't just memorise the answer — build a daily practice habit.

Practice 5 Similar Questions Free →

All Input-Output practice questions

More Input-Output practice

A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…