• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            CG@CPPBLOG

            /*=========================================*/
            隨筆 - 76, 文章 - 39, 評論 - 137, 引用 - 0
            數據加載中……

            我的SICP習題答案(1.29~1.33)

            1.29

            (define (simpson f a b n)
              (define (get-h) (/ (- b a) n))
              (define (get-y k) (f (+ a (* k (get-h)))))
              (define (simpson-term k)
                (cond ((
            = k 0) (get-y k))
                      ((
            = k n) (get-y k))
                      ((
            = (remainder k 20) (* 2.0 (get-y k)))
                      (else (* 
            4.0 (get-y k)))))
              (define (simpson-next k) (+ k 
            1))
              (* (/ (get-h) 
            3.0) (sum simpson-term 0 simpson-next n))) 

            1.30

            (define (sum term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (+ (term a) result))))
              (iter a 
            0))

            1.31

            ;;遞歸
            (define (product-re term a next b)
              (if (> a b)
                  
            1
                  (* (term a)
                     (product-re term (next a) next b))))
            ;;迭代
            (define (product term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (* result (term a)))))
              (iter a 
            1))

            (define (pi-product b)
              (define (pi-term k) (/ (* (- k 
            1) (+ k 1)) k k))
              (define (pi-next k) (+ k 
            2))
              
            ;;(* 4.0 (product-re pi-term 3.0 pi-next b))) ;;遞歸
              (* 4.0 (product pi-term 3.0 pi-next b)))      ;;迭代


            1.32

            (define (sum term a next b)
              (accumulate + 
            0 term a next b))

            (define (product term a next b)
              (accumulate * 
            1 term a next b))

            ;;遞歸
            (define (accumulate-re combiner null-value term a next b)
              (if (> a b)
                  null-value
                  (combiner (term a)
                            (accumulate-re combiner null-value term (next a) next b))))

            ;;迭代
            (define (accumulate combiner null-value term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (combiner (term a) result))))
              (iter a null-value))

            1.33

            (define (filtered-accumulate combiner null-value term a next b filter?)
              (define (iter a result)
                (if (> a b)
                    result
                    (if (filter? (term a))
                        (iter (next a) (combiner (term a) result))
                        (iter (next a) result))))
              (iter a null-value))

            (define (sum-prime a b)
              (define (sum-prime-term k) k)
              (define (sum-prime-next k) (+ k 
            1))
              (filtered-accumulate + 
            0 sum-prime-term a sum-prime-next b prime?))

            (define (relatively-prime-product n)
              (define (relatively-prime? k) (
            = (gcd k n) 1))
              (define (term k) k)
              (define (next k) (+ k 
            1))
              (filtered-accumulate * 
            1 term 2 next (- n 1) relatively-prime?))



            posted on 2008-04-06 16:12 cuigang 閱讀(944) 評論(0)  編輯 收藏 引用 所屬分類: Lisp/Scheme我的SICP答案

            国产亚洲精久久久久久无码77777| 少妇久久久久久久久久| 2021久久国自产拍精品| 久久99国产精品久久| 久久国产精品久久国产精品| 狠狠色丁香婷婷久久综合不卡 | 日韩精品久久无码人妻中文字幕| 久久人人爽人人爽人人片AV东京热 | 色综合久久天天综合| 久久国产视屏| 国产69精品久久久久APP下载 | 国产成人精品综合久久久| 人妻丰满AV无码久久不卡| 久久久久久九九99精品| 国产成人AV综合久久| 久久亚洲精品国产亚洲老地址| 久久午夜无码鲁丝片秋霞| 国产成人久久精品区一区二区| 国内精品久久久久影院网站| 亚洲香蕉网久久综合影视| 精品午夜久久福利大片| 久久午夜夜伦鲁鲁片免费无码影视| 97久久天天综合色天天综合色hd| 久久久这里有精品中文字幕| 久久超乳爆乳中文字幕| 午夜精品久久久久久影视riav| 国产精品99久久精品| 久久亚洲国产成人影院| 国产精品成人无码久久久久久| 久久伊人五月丁香狠狠色| 久久中文精品无码中文字幕| 久久精品水蜜桃av综合天堂 | 一本大道久久东京热无码AV| 狠狠干狠狠久久| 婷婷综合久久中文字幕蜜桃三电影| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 思思久久99热免费精品6| 2020最新久久久视精品爱| 精品无码久久久久久尤物| 2021国产精品午夜久久| 久久久久国产一区二区|