Last active
October 7, 2017 05:39
-
-
Save JadenGeller/566a0c75ae1effc944af325b9a30d570 to your computer and use it in GitHub Desktop.
Idris Spiral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Vect | |
Matrix : Nat -> Nat -> Type -> Type | |
Matrix r c a = Vect r (Vect c a) | |
unrotate : Matrix r c a -> Matrix c r a | |
unrotate = reverse . transpose | |
spiral : Matrix r c a -> Vect (r * c) a | |
spiral {r=Z} [] = [] | |
spiral {r=S r'} {c} (row :: rows) = let rest : Vect (r' * c) a = rewrite multCommutative r' c | |
in spiral (unrotate rows) | |
in row ++ rest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment