fork download
  1. ; array rotation
  2.  
  3. (define (rotate ary len dist)
  4. (do ((idx 0 (+ idx 1))) ((= idx (gcd dist len)) ary)
  5. (let ((temp (vector-ref ary idx)))
  6. (do ((lo idx hi) (hi (modulo (+ idx dist) len) (modulo (+ hi dist) len)))
  7. ((= hi idx) (vector-set! ary lo temp))
  8. (vector-set! ary lo (vector-ref ary hi))))))
  9.  
  10. (display (rotate '#(a b c d e f g h) 8 3)) (newline)
Success #stdin #stdout 0.04s 8224KB
stdin
Standard input is empty
stdout
#(d e f g h a b c)