#:g1: GOOでL-99 (P19 指定した位置でローテーション)

Posted 2008-06-05 14:11:00 GMT

-(http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
P17で定義したmy-splitを使います。

(rotate '(a b c d e f g h) 3)
;=> (d e f g h a b c)
(rotate '(a b c d e f g h) -2)
;=> (g h a b c d e f)
(rotate #[a b c d e f g h] 3)
;=> #[d e f g h a b c]
(rotate #(a b c d e f g h) -2)
;=> #(g h a b c d e f)
(rotate "abcdefgh" 3)
;=> "defghabc"
(rotate "abcdefgh" -2)
;=> "ghabcdef"

(dg rotate (u|<seq> p|<int> => <seq>))

(dm rotate (u|<seq> p|<int> => <seq>) (def p (if (> 0 p) (+ p (len u)) p)) (app cat (rev (as <lst> (my-split u p)))))


comments powered by Disqus