fork download
  1. ; partial products of an array
  2.  
  3. (define (take n xs)
  4. (let loop ((n n) (xs xs) (ys '()))
  5. (if (or (zero? n) (null? xs))
  6. (reverse ys)
  7. (loop (- n 1) (cdr xs)
  8. (cons (car xs) ys)))))
  9.  
  10. (define (scanl op base xs)
  11. (let loop ((xs xs) (base base) (zs (list base)))
  12. (if (null? xs) (reverse zs)
  13. (let ((z (op (car xs) base)))
  14. (loop (cdr xs) z (cons z zs))))))
  15.  
  16. (define (f xs)
  17. (let* ((len (length xs))
  18. (left (take len (scanl * 1 xs)))
  19. (right (reverse (take len (scanl * 1 (reverse xs))))))
  20. (map * left right)))
  21.  
  22. (display (f '(1 2 3 4 5))) (newline)
  23. (display (f '(5 3 4 2 6 8))) (newline)
Success #stdin #stdout 0.02s 42848KB
stdin
Standard input is empty
stdout
(120 60 40 30 24)
(1152 1920 1440 2880 960 720)