Reputation: 3633
Say I have a list of lists of a type: can I rotate it (in a sense) so that:
[[a,b], [[b,d],
[c,d]] => [a,c]]
For any size list? Or if not possible for arbitrary sized list just for a list of size 6x6
Upvotes: 2
Views: 507
Reputation: 15078
The following should give you the desired output:
import Data.List (transpose)
rotate :: [[a]] -> [[a]]
rotate = reverse . transpose
Testing:
*Main> rotate [[1,2],[3,4]]
[[2,4],[1,3]]
*Main> rotate [[1,2,3],[4,5,6],[7,8,9]]
[[3,6,9],[2,5,8],[1,4,7]]
Upvotes: 9