Advertisement
PonaFly

Untitled

Feb 21st, 2019
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.33 KB | None | 0 0
  1. ;2
  2. (define (sumFib lst)
  3.   (define l (length lst))
  4.   (define (iter a b sum)
  5.     (if (= 1 l) (car lst)
  6.     (if(< a l)
  7.        (iter b (+ a b) (+ (list-ref lst a) sum))
  8.        (- sum (cadr lst)))))
  9.   (iter 0 1 0))
  10.  
  11.  
  12.  
  13. ;3
  14. (define (function1 x y)
  15.   (define (fact n)
  16.   (define (fun  x lst i)
  17.    (if (or (> i n) (= i x)) (reverse (cons i lst))
  18.        (if (= (remainder x i) 0) (fun (/ x i) (cons i lst) i)
  19.            (fun x  lst (+ i 1)) )))
  20.   (fun n '() 2))
  21. (define (Fun lst)
  22.   (define (fun ans lest )
  23.     (if (empty? lest) #t
  24.         (if (member (car lest) ans) #f
  25.             (fun (cons (car lest) ans) (cdr lest) ))))
  26.   (fun '() lst ))
  27.  (define (del n)
  28.     (if (Fun (fact n)) #f #t))
  29.   (define (otr a b)
  30.  (define (fun2 i ans)
  31.   (if (> i b) (reverse ans)
  32.       (fun2 (add1 i) (cons i ans))))
  33.   (fun2 a '()))
  34.   (filter del (otr x y)))
  35.  
  36.  
  37. ; первая задача
  38. (define (derivative lst)
  39.   (define (fun z n a)
  40.     (if (empty? z) #f
  41.      (if (= 1 (length z)) (reverse n)
  42.             (fun (cdr z) (cons (* (car z) (- a 1)) n) (- a 1)))))
  43.   (fun lst '() (length lst)))
  44.  
  45. ; 2 task
  46.  
  47. (define (Sum lst1 lst2 )
  48.  (define a (length lst1))
  49.  (define b (length lst2))
  50.   (cond ((= a b)(map + lst1 lst2))
  51.    ((< a b)(map + (append (make-list (- b a) 0) lst1) lst2))
  52.    ((< b a)(map + (append (make-list (- a b) 0) lst2) lst1))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement