I have a problem to unfold a matrix. Here is how the output of the programm should look like. I am little bit stuck.
unfoldMatrix :: [ [a] ] -> [a]
Main> unfoldMatrix [[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]]
[1,4,7,10,11,12,9,6,3,2,5,8]
My code works but it’s output is in this format
[[1,4,7],[8,9],[6,3],[2],[5],[]]
Any ideat how to change the code to work as wanted?
transpose2:: [[a]]->[[a]]
transpose2 ([]:_) = []
transpose2 x = (map head x) : transpose2 (map tail x)
unfoldMatrix:: [[a]]->[[a]]
unfoldMatrix ([]:_) = []
unfoldMatrix x =(map head x):unfoldMatrix(tail2(x))
rotate90 :: [ [ a ] ] -> [ [ a ] ]
rotate90 = (map reverse).transpose2
tail2:: [[a]]->[[a]]
tail2 = (tail).rotate90
You don’t need
transpose2, if all sublists are equally long, that’s the same astransposefromData.List. So your unfold would simply be