Commits

Shlomi Fish committed f96b10d

Refactored.

  • Participants
  • Parent commits 15bc3dd

Comments (0)

Files changed (1)

shlomif-racket-playground/squares-inside-squares.rkt

 (define (seq start end)
   (for/list ([i (in-range start end)]) i))
 
+(define (accum-list fn start count)
+  (if (= count 0)
+      '()
+      (cons start (accum-list fn (fn start) (- count 1)))))
+
 (define (my-squares angle-in-degs count)
   (let* ([angle (degrees->radians angle-in-degs)]
          [offset 100]
          [my-inset (lambda (offset pict) (inset pict offset offset))])
     (my-inset offset
       (apply lt-superimpose
-              (foldl  {lambda (a result)
-                  (cons {scale (rotate (car result) angle)
-                         (sqrt (+ (expt angle 2) (expt (- 1 angle) 2)))} result)}
-               (list (my-inset (- offset) (rectangle size size))) (seq 1 count))))))
+              (accum-list  (lambda (x)
+                  {scale (rotate x angle)
+                         (sqrt (+ (expt angle 2) (expt (- 1 angle) 2)))})
+               (my-inset (- offset) (rectangle size size)) count)))))