Created
February 15, 2014 18:25
-
-
Save liamgriffiths/9023179 to your computer and use it in GitHub Desktop.
rotate a matrix 90 degrees to the right in scheme
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
(define (transpose m) | |
(apply map list m)) | |
(define (rotate-90 m) | |
(transpose (reverse m))) | |
(define matrix | |
(list (list 'a 'b 'c 'd) | |
(list 'e 'f 'g 'h) | |
(list 'i 'j 'k 'l) | |
(list 'm 'n 'o 'p))) | |
(define rotated-matrix | |
(list (list 'm 'i 'e 'a) | |
(list 'n 'j 'f 'b) | |
(list 'o 'k 'g 'c) | |
(list 'p 'l 'h 'd))) | |
(equal? (rotate-90 matrix) rotated-matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment