Skip to content

Instantly share code, notes, and snippets.

@liamgriffiths
Created February 15, 2014 18:25
Show Gist options
  • Save liamgriffiths/9023179 to your computer and use it in GitHub Desktop.
Save liamgriffiths/9023179 to your computer and use it in GitHub Desktop.
rotate a matrix 90 degrees to the right in scheme
(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