i've created image using lists of type string. kind of
pic 1 = ["xxxx", "x ", "xxx ", "x ", "xxxx"]
so i'm trying create 90 degrees rotation (clockwise). code have far, seems work level not on images.
rotateline90 :: pic -> int -> [char] rotateline90 pic n = reverse [line!!n | line<-pic] rotate90 :: pic -> pic rotate90 pic = [rotateline90 pic | i<-[0 .. (length pic) - 1]]
any ideas on how improve code.
this works
rotate90 = (map reverse .) $ foldr (zipwith (:)) $ repeat ""
usage:
> rotate90 ["xxxx", "x ", "xxx ", "x ", "xxxx"] ["xxxxx","x x x","x x x","x x"]
Comments
Post a Comment