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: 33 harbor 59 pilot 42 raven 17 vessel.
Which of the following is the last step of the above arrangement?

Competition practiceInput-Output
  • A42 33 59 17 harbor pilot raven vessel
  • B17 33 42 59 harbor pilot raven vessel
  • C17 59 33 42 harbor pilot raven vessel
  • D42 33 59 17 vessel raven pilot harbor

Step-by-Step Solution

Primes: 59 and 17. Not prime: 33 (3 times 11) and 42. Order of shifting: 17, 59, then 33, then 42. Step 1: 17 33 harbor 59 pilot 42 raven vessel. Step 2: 59 17 33 harbor pilot 42 raven vessel. Step 3: 33 59 17 harbor pilot 42 raven vessel. Step 4: 42 33 59 17 harbor pilot raven vessel. Since every number lands at the extreme left, the final block reads in the reverse of the order in which the numbers were shifted — writing 17 59 33 42 records the shifting order instead of the finished line, and 17 33 42 59 is what a plain ascending sort would have given had primeness been ignored. The words are never moved, so they stay as harbor, pilot, raven, vessel.
Answer: A) 42 33 59 17 harbor pilot raven vessel

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,…