Click here to Skip to main content
15,797,721 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

I am following some tutorials and online training courses and I encountered task I don't really understand. I would be happy if someone can help me write the code. I usually code in Python, but any language will help as long as I understand the logic of it!

Thank you very much!

The logical problem:

def get_reversals_to_sort(self, a)
You need to sort an array of integers by repeatedly reversing
the order of the first several elements of it.

For example, to sort [11,14,12,13], you need to reverse the order of the
first two (2)
elements and get [14,11,12,13], then reverse the order of the first four (4)
and get [13,12,11,14] and then reverse the order of the first three (3)

The method should return array of integers corresponding to the required
For the previous example, given an array [11,14,12,13]
the method should return a array with integers [2,4,3].

:param a: list of numbers
:returns: list of numbers

What I have tried:

I am sorry, I have not tried anything so far, because I don't understand how it works...:/
Updated 26-Oct-17 6:49am
Richard MacCutchan 26-Oct-17 9:36am    
That method will only work for that sample.
Member 13487117 26-Oct-17 9:45am    
what... "method"? :) I am sorry, as I said, I don't understand logic of the problem...
Richard MacCutchan 26-Oct-17 9:49am    
The method that you have put in your question. You should be posing this question to the person who wrote the tutorial.

1 solution

Who has written this qoute. If there isnt some sorting logic in swapping nothing get sorted. Somewhere must be checked whether to swap some elements.

There a lot of Sorting algorithm out there.

Your qoute sounds a bit like quicksort. Very mysterous and not solvable...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900