I found a problem on Rosalind Problem : Reversal Distance
I use brut force search for all possible swap . and Get following result of the sample data.
['3', '1', '5', '2', '7', '4', '9', '6', '10', '8']
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
0 1 1 ['2', '1', '3', '4', '5', '6', '7', '8', '9', '10'] 1
0 2 1 ['3', '1', '2', '4', '5', '6', '7', '8', '9', '10'] 2
2 3 1 ['3', '1', '4', '2', '5', '6', '7', '8', '9', '10'] 3
2 4 1 ['3', '1', '5', '2', '4', '6', '7', '8', '9', '10'] 4
4 5 1 ['3', '1', '5', '2', '6', '4', '7', '8', '9', '10'] 5
4 6 1 ['3', '1', '5', '2', '7', '4', '6', '8', '9', '10'] 6
6 7 1 ['3', '1', '5', '2', '7', '4', '8', '6', '9', '10'] 7
6 8 1 ['3', '1', '5', '2', '7', '4', '9', '6', '8', '10'] 8
8 9 1 ['3', '1', '5', '2', '7', '4', '9', '6', '10', '8'] 9
--------------------------------------------------------------------------------
['5', '2', '3', '1', '7', '4', '10', '8', '6', '9']
['3', '10', '8', '2', '5', '4', '7', '1', '6', '9']
0 3 2 ['5', '2', '8', '10', '3', '4', '7', '1', '6', '9'] 1
2 6 2 ['5', '2', '1', '7', '3', '4', '10', '8', '6', '9'] 2
2 3 1 ['5', '2', '7', '1', '3', '4', '10', '8', '6', '9'] 3
2 4 1 ['5', '2', '3', '1', '7', '4', '10', '8', '6', '9'] 4
--------------------------------------------------------------------------------
['8', '2', '7', '6', '9', '1', '5', '3', '10', '4']
['8', '6', '7', '9', '4', '1', '3', '10', '2', '5']
6 8 2 ['8', '6', '7', '9', '4', '1', '5', '2', '10', '3'] 1
1 3 1 ['8', '9', '7', '6', '4', '1', '5', '2', '10', '3'] 2
1 4 1 ['8', '4', '7', '6', '9', '1', '5', '2', '10', '3'] 3
1 7 1 ['8', '2', '7', '6', '9', '1', '5', '4', '10', '3'] 4
7 9 1 ['8', '2', '7', '6', '9', '1', '5', '3', '10', '4'] 5
--------------------------------------------------------------------------------
['2', '9', '8', '5', '1', '7', '3', '4', '6', '10']
['3', '9', '10', '4', '1', '8', '6', '7', '5', '2']
2 8 2 ['3', '9', '2', '5', '1', '8', '6', '7', '4', '10'] 1
0 2 1 ['2', '9', '3', '5', '1', '8', '6', '7', '4', '10'] 2
2 5 1 ['2', '9', '8', '5', '1', '3', '6', '7', '4', '10'] 3
5 6 1 ['2', '9', '8', '5', '1', '6', '3', '7', '4', '10'] 4
5 7 1 ['2', '9', '8', '5', '1', '7', '3', '6', '4', '10'] 5
7 8 1 ['2', '9', '8', '5', '1', '7', '3', '4', '6', '10'] 6
--------------------------------------------------------------------------------
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
The problem is my answer of data 3 is 6 not 7 !
Due to my bad formating, you can do the swap by the 3 number.
0 3 2 : swap at 0 to 3 with length 2
PS.I know why.
The problem description refers to reversing an entire interval of the set, not swapping various parts of it.
Check it in Problem's Question.
Recent Comments