Cody

# Problem 42920. Find the inverse permutation

Solution 1213975

Submitted on 16 Jun 2017 by Jeroen Cottaar
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
for permlength = 1:100 perm = randperm(permlength); invPerm = inversePermutation(perm); assert(isequal(perm(invPerm),1:permlength)) end

invPerm = 1 invPerm = 2 1 invPerm = 1 3 2 invPerm = 4 1 2 3 invPerm = 4 2 5 3 1 invPerm = 2 6 1 3 4 5 invPerm = 3 7 6 2 4 5 1 invPerm = 1 5 7 6 8 3 4 2 invPerm = 5 2 6 1 4 9 3 8 7 invPerm = 4 3 7 6 5 2 9 10 8 1 invPerm = 9 4 7 6 11 8 3 5 2 10 1 invPerm = 4 9 3 1 7 11 5 2 6 12 8 10 invPerm = 4 7 13 6 2 3 1 12 9 8 5 11 10 invPerm = 9 5 1 8 14 13 2 7 6 4 12 3 11 10 invPerm = 1 5 15 9 2 6 3 12 11 7 10 13 14 4 8 invPerm = 12 10 8 4 7 5 6 9 2 13 11 3 16 1 14 15 invPerm = 13 6 1 9 2 5 11 10 8 7 12 3 14 15 16 17 4 invPerm = 1 11 6 7 8 2 17 5 10 15 13 14 3 18 12 9 16 4 invPerm = 14 13 8 19 9 1 3 11 10 12 16 6 2 17 15 4 7 5 18 invPerm = 4 5 17 14 10 20 19 1 18 2 16 13 11 15 3 12 9 8 6 7 invPerm = 12 6 2 18 9 5 8 21 19 11 1 4 15 7 13 16 14 20 3 10 17 invPerm = 15 11 12 7 3 4 13 1 19 20 21 17 22 10 8 14 5 6 9 16 18 2 invPerm = 21 4 19 18 16 7 17 8 15 9 3 10 14 22 12 2 23 6 13 5 11 1 20 invPerm = 4 18 21 24 19 16 3 7 23 9 12 2 17 13 22 6 11 8 20 15 14 10 5 1 invPerm = 15 6 3 7 24 19 18 17 22 14 16 12 25 21 10 5 20 13 11 9 4 2 1 23 8 invPerm = 2 22 4 16 5 6 10 18 8 14 9 11 24 12 19 25 21 7 13 17 23 26 15 1 3 20 invPerm = 26 11 25 17 7 19 20 18 5 2 12 16 14 10 8 23 27 21 6 9 3 22 1 15 4 13 24 invPerm = 11 27 20 12 9 18 15 21 24 17 13 16 5 23 6 4 1 25 22 3 14 10 7 28 2 26 19 8 invPerm = 6 21 8 20 7 22 11 29 18 10 15 5 17 16 12 23 2 14 28 25 4 13 26 19 3 24 9 27 1 invPerm = Columns 1 through 29 30 17 5 15 6 14 27 24 19 25 2 9 16 4 3 23 29 7 22 10 1 12 21 18 20 28 13 11 26 Column 30 8 invPerm = Columns 1 through 29 25 3 5 9 28 24 16 13 12 6 7 19 1 11 20 26 18 14 23 30 4 10 17 27 2 8 31 21 22 Columns 30 through 31 29 15 invPerm = Columns 1 through 29 18 7 3 15 20 16 9 25 32 2 27 13 5 29 26 11 23 8 1 22 10 21 4 12 28 17 14 24 31 Columns 30 through 32 6 30 19 invPerm = Columns 1 through 29 2 30 16 6 8 14 10 22 27 3 32 1 26 29 5 21 15 23 7 25 11 33 4 28 31 13 24 20 18 Columns 30 through 33 19 12 17 9 invPerm = Columns 1 through 29 27 4 34 32 2 10 12 24 7 21 33 3 15 28 25 8 1 19 5 18 17 6 14 30 26 23 29 11 22 Columns 30 through 34 20 16 31 13 9 invPerm = Columns 1 through 29 14 8 7 11 18 33 12 9 22 5 3 34 4 30 2 24 6 29 25 20 15 1 31 32 10 26 27 35 19 Columns 30 through 35 17 16 21 23 13 28 invPerm = Columns 1 through 29 27 20 3 9 7 11 10 1 35 21 22 25 13 32 12 17 34 23 5 2 28 8 6 4 30 16 33 26 36 Columns 30 through 36 24 15 18 31 19 14 29 invPerm = Columns 1 through 29 32 14 11 37 25 27 34 26 20 22 7 30 31 24 33 36 10 4 16 35 3 5 2 17 19 6 15 18 28 Columns 30 through 37 21 29 1 9 8 23 13 12 invPerm = Columns 1 through 29 28 36 20 14 2 25 3 11 12 19 27 29 9 26 18 21 33 22 7 30 32 15 10 38 5 13 24 37 34 Columns 30 through 38 6 4 16 23 31 17 35 1 8 invPerm = Columns 1 through 29 15 26 30 33 18 11 12 17 19 6 2 10 28 34 14 1 5 39 20 38 31 8 25 3 9 13 21 32 37 Columns 30 through 39 22 35 23 36 24 16 4 27 7 29 invPerm = Columns 1 through 29 24 13 22 35 40 33 18 4 14 9 5 39 28 38 2 34 19 36 23 8 25 12 37 15 16 7 10 26 29 Columns 30 through 40 31 30 6 3 21 27 20 11 1 17 32 invPerm = Columns 1 through 29 32 15 30 23 34 25 12 1 10 19 4 2 41 14 5 22 21 3 26 40 29 37 27 28 7 36 24 39 20 Columns 30 through 41 11 8 9 31 16 38 33 17 18 6 13 35 invPerm = Columns 1 through 29 41 16 12 25 5 38 31 24 19 34 33 29 39 17 15 37 20 14 8 10 2 23 36 28 35 9 21 6 42 Columns 30 through 42 32 1 22 13 30 7 27 26 18 40 3 4 11 invPerm = Columns 1 through 29 39 43 37 18 12 16 11 29 3 20 17 14 1 10 31 30 22 42 13 23 9 8 34 6 33 5 21 15 4 Columns 30 through 43 36 2 19 25 40 26 32 38 24 35 28 27 7 41 invPerm = Columns 1 through 29 1 34 15 26 33 23 2 43 11 7 30 17 29 32 28 8 27 14 37 42 3 22 4 24 41 13 20 19 38 Columns 30 through 44 6 5 35 16 36 10 12 40 39 21 31 25 18 44 9 invPerm = Columns 1 through 29 11 31 9 4 19 3 29 30 16 23 35 38 45 1 17 42 33 27 21 12 34 32 28 20 15 6 14 26 2 Columns 30 through 45 22 36 7 10 39 25 18 13 37 8 41 5 24 43 44 40 invPerm = Columns 1 through 29 1 36 43 5 23 44 21 34 25 30 18 32 29 8 2 20 35 37 4 11 28 31 9 33 22 39 19 10 15 Columns 30 through 46 26 40 42 41 16 45 17 6 46 12 27 3 24 7 13 38 14 invPerm = Columns 1 through 29 5 2 16 29 4 9 45 28 46 12 19 47 26 42 40 1 21 22 10 8 35 34 39 7 31 32 41 25 3 Columns 30 through 47 6 20 14 24 30 23 15 44 33 13 37 18 17 36 11 38 43 27 invPerm = Columns 1 through 29 45 7 48 31 14 11 6 30 37 29 40 9 36 46 15 2 22 24 10 4 35 5 25 16 32 12 43 39 44 Columns 30 through 48 26 20 34 23 1 42 28 19 33 13 27 8 18 17 41 21 47 3 38 invPerm = Columns 1 through 29 30 20 13 41 10 28 15 2 46 21 34 16 32 39 25 26 43 9 27 14 8 45 5 35 3 48 42 24 40 Columns 30 through 49 11 22 36 6 18 4 31 37 33 23 1 7 29 17 44 49 47 19 38 12 invPerm = Columns 1 through 29 35 7 30 33 20 15 5 9 24 25 19 31 38 40 28 44 39 2 47 27 21 41 43 36 45 8 13 17 34 Columns 30 through 50 48 42 10 29 3 1 46 32 4 16 50 11 26 18 22 37 49 14 6 23 12 invPerm = Columns 1 through 29 10 3 37 19 48 9 29 14 42 31 32 1 2 33 13 8 21 18 35 5 34 20 15 36 23 45 44 46 4 Columns 30 through 51 43 51 40 39 49 28 16 24 11 47 6 12 30 38 25 50 17 22 26 41 7 27 invPerm = Columns 1 through 29 4 31 20 3 25 46 39 15 48 32 14 52 2 13 37 11 47 9 33 51 10 19 21 49 26 16 45 42 50 Columns...