2023-9: Flipping Pairs
This problem has no practical use in the real world (that the author can think of) other than to give your array manipulation muscles some exercise.
Write a function that:
- takes a non-empty non-scalar array right argument
- returns an array of the same shape as the argument, but with pairs of elements along the last axis "flipped". If the array has an odd number of elements in the last axis, leave the last element unchanged.
Hint: Either the reverse function ⌽ used with the partitioned enclose function ⊂, or the grade up function ⍋ used with the index function ⌷, could be helpful in solving this problem.
Examples:
(your_function) ⍳10 2 1 4 3 6 5 8 7 10 9 (your_function) ⍳9 2 1 4 3 6 5 8 7 9 (your_function) 4 2⍴⍳8 2 1 4 3 6 5 8 7 (your_function) 4 3⍴⍳12 2 1 3 5 4 6 8 7 9 11 10 12 (your_function) 3 3 3⍴⍳27 2 1 3 5 4 6 8 7 9 11 10 12 14 13 15 17 16 18 20 19 21 23 22 24 26 25 27 (your_function) 2 3⍴'donald' 'duck' 'wrote' 'some' 'good' 'APL' ┌────┬──────┬─────┐ │duck│donald│wrote│ ├────┼──────┼─────┤ │good│some │APL │ └────┴──────┴─────┘
your_function ←
Solutions

