2.20

 
;2.20
(define (check i)
    (if (= 0 (remainder i 2)) 0 1))

(define (same-parity . w)
  (define flag (check (car w)))
  (define (iter i items)
      (if (= i (length w))
          (my-reverse items)
          (if (= (check (list-ref w i))
                 flag)
              (iter (+ 1 i) (cons (list-ref w i) items))
              (iter (+ 1 i) items))))
  (iter 0 '()))

;midterm examle 1 problem 5
(define (vowel? letter)
  (member? letter '(a e o u i)))

(define (syllables wds)
  (define (iter letter count strings)
    (cond ((= '() (first strings)) count)
          ((vowel? (first strings)) (if (not (vowel? letter))
                                        (iter (first strings) (+ 1 count) (butfirst strings)))
                                   )
          (else (iter (first strings count (butfirst strings))))))
  (iter '() 0 wds))

;map tree
(define (scale-tree tree factor)
  (cond ((null? tree) '())
        ((not (pair? tree)) (* tree factor))
        (else (cons (scale-tree (car tree) factor)
                    (scale-tree (cdr tree) factor)))))

(define (s-tree tree factor)
  (map (lambda (sub-tree)
         (if (pair? sub-tree)
             (scale-tree sub-tree factor)
             (* sub-tree factor)))
       tree))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值