読者です 読者をやめる 読者になる 読者になる

(wat-aro)

無職から有職者にランクアップしました

SICP 問題 2.52

scheme SICP
         (make-segment (make-vect 0.582 0.657) (make-vect 0.640 0.857))
         (make-segment (make-vect 0.640 0.857) (make-vect 0.575 1.000))
         (make-segment (make-vect 0.419 1.000) (make-vect 0.354 0.857))
         (make-segment (make-vect 0.354 0.857) (make-vect 0.411 0.657))
         (make-segment (make-vect 0.411 0.657) (make-vect 0.285 0.657))
         (make-segment (make-vect 0.285 0.657) (make-vect 0.154 0.605))
         (make-segment (make-vect 0.154 0.605) (make-vect 0.000 0.857)))))

;; b
(define (corner-split painter n)
  (if (= n 0)
      painter
      (let ((up (up-split painter (- n 1)))
            (right (right-split painter (- n 1)))
            (corner (corner-split painter (- n 1))))
        (beside (below painter up)
                (below painter right corner)))))

;; c
(define (corner-split painter n)
  (if (= n 0)
      (flip-horiz painter)
      (let ((up (up-split painter (- n 1)))
            (right (right-split painter (- n 1))))
        (let ((top-left (beside up up))
              (bottom-right (below right right))
              (corner-split (painter (- n 1))))
          (beside (below painter top-left)
                  (below bottom-right corner))))))