How to define a rotates function

后端 未结 8 1948
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 14:47

How to define a rotates function that generates all rotations of the given list?

For example: rotates [1,2,3,4] =[[1,2,3,4],[2,3,4,1],[3,4,1,2],[4,1,2,3]]

8条回答
  •  攒了一身酷
    2021-01-11 15:33

    myRotate lst = lst : myRotateiter lst lst
      where myRotateiter (x:xs) orig
              |temp == orig = []
              |otherwise = temp : myRotateiter temp  orig               
              where temp = xs ++ [x]
    

提交回复
热议问题