Advertisement
PonaFly

Untitled

Mar 14th, 2019
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.07 KB | None | 0 0
  1. ;1 c прошлой лабы
  2.  
  3. (define (splitting lst n r1 r2 r3 l1 l2 l3)  
  4.   (if (and (= n l1)  (= n l2) (= n l3)) (list r1 r2 r3)    
  5.        ( cond((and  (<(length r1)n) (= 0 (remainder (car lst) 3)))
  6.                   (splitting (cdr lst) n (cons (car lst) r1) r2 r3 (+ 1 l1) l2 l3))
  7.              ((and (< (length r2) n) (= 1 (remainder (car lst) 3)))
  8.               (splitting (cdr lst) n r1 (cons (car lst) r2) r3 l1 (+ 1 l2) l3))
  9.              ( (and (<(length r3) n) (= 2 (remainder (car lst) 3)))
  10.                (splitting (cdr lst) n r1 r2 (cons (car lst) r3) l1 l2 (+ 1 l3)))
  11.  (else (splitting (cdr lst) n r1 r2 r3 l1 l2 l3)))))
  12. (define (main lst N)
  13.   (define (threelist lst res)
  14.     (if (empty? (car lst)) res
  15.         (threelist (list(cdar lst) (cdadr lst) (cdaddr lst)) (cons (list(caar lst) (caadr lst) (caaddr lst)) res))))
  16.   (threelist (splitting lst N '() '() '() 0 0 0) '()))
  17.  
  18.  
  19.  
  20. ;3 задача c прошлой
  21.  
  22. (define (Maxtree tree)
  23.   (if (empty? tree) -999999000000
  24.       (max (car tree) ( max (Maxtree (cadr tree)) (Maxtree (caddr tree))))))
  25. (define (CountMax tree)
  26.   (define Max (Maxtree tree))
  27.   (define (FunctionMax tree1 )
  28.      (if (empty? tree1) 0
  29.       (+ (if (= (car tree1) Max) 1 0)
  30.          (FunctionMax (cadr tree1)) (FunctionMax (caddr tree1)))))
  31.   (FunctionMax tree))
  32.  
  33.  
  34. ;5 задача с прошлой
  35.  
  36.  
  37. (define (KidsTree tree)
  38.   (if (empty? tree) #t
  39.       (cond ((or (and (empty? (cadr tree)) (not (empty? (caddr tree)))) (and (not (empty? (cadr tree))) (empty? (caddr tree))))#f )
  40.             ((and (empty? (cadr tree)) (empty? (caddr tree))) #t)
  41.            (else  (and (KidsTree (cadr tree)) (KidsTree (caddr tree)))) )))
  42.  
  43. ; 3 pflfxf
  44.  
  45. (define (LeftTree tree)
  46.   (define (lefttree tree )
  47.      (if (empty? tree) 0
  48. (+ (if (not (empty? (cadr tree))) 1 0)
  49.    (lefttree (cadr tree)) (lefttree (caddr tree)))))
  50. (lefttree tree ))
  51.  
  52.  
  53. ;4 pflfxf
  54. (define (Minlist tree)
  55.   (if (empty? tree) +inf.0
  56.       (if (and (empty? (cadr tree)) (empty? (caddr tree))) (car tree)
  57.             (min (Minlist (cadr tree) (Minlist (caddr tree)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement