
Robot Sort
The spaceship reactors contains several (no more than ten) nuclear fuel rods. These rods should be sorted by size to ensure the reactor’s stability, but as usual the fuel rod loading mechanism malfunctioned and inserted the rods at random, then started the ships engine. Now Stephan has to reload the rods all over again. Because the reactor is already running, he needs to quickly swap neighbouring rods or else the whole thing goes BOOM!
You are given the sizes and initial order of the rods as an array of numbers. Indexes are position, values are sizes. You should order this array from the smallest to the largest in size.
For each action Stephan can swap only two neighbouring elements. Each action should be represented as a string with two digits - indexes of the swapped elements (ex, "01" - swap 0th and 1st rods). The result should be represented as a string that contains the sequence of actions separated by commas. If the array does not require sorting, then return an empty string.
And you can swap only N*(N-1)/2 times, where N - is a quantity of rods.
Input: An array as a tuple of integers.
Output: The sequence of actions as a string.
Example:
swapsort((6, 4, 2)) == "01,12,01" swapsort((1, 2, 3, 4, 5)) == "" swapsort((1, 2, 3, 5, 3)) == "43"
How it is used: This mission will show you how to work the simplest sorting algorithms. And this can be useful, if you need to build a production line for your factory.
Precondition:
1 ≤ len(
array
) ≤ 10
all(1 ≤ n < 10 for n in
array
)
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
checkio sync
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium
Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.