Advertisement
Guest User

Untitled

a guest
Dec 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.16 KB | None | 0 0
  1.  
  2. (define (rmvfrom elem seq)
  3.     (cond   ((null? seq) '())
  4.             ((= elem (car seq)) '())
  5.             (else (cons (car seq) (rmvfrom elem (cdr seq))))
  6.     )
  7. )
  8.  
  9.  
  10. (define (maax a b)
  11.     (if (> (length a) (length b)) a b)
  12. )
  13.  
  14. (define (uniq seq)
  15.     (if (null? seq) '(() ())
  16.         (let ((next (uniq (cdr seq))))
  17.             (let ((cur (cons (car seq) (rmvfrom (car seq) (car next)))))
  18.                 (list cur (maax cur (cadr next)))
  19.             )
  20.         )
  21.     )
  22. )
  23.  
  24. (define (longestUniqum seq)
  25.     (cadr (uniq seq))  
  26. )
  27.  
  28. (display (longestUniqum '(3 4 1 2)))(newline)
  29. (display (longestUniqum '(2 3 4 1 2)))(newline)
  30. (display (longestUniqum '(4 2 3 4 1 2)))(newline)
  31. (display (longestUniqum '(3 4 2 3 4 1 2)))(newline)
  32. (display (longestUniqum '(2 3 4 2 3 4 1 2)))(newline)
  33. (display (longestUniqum '(1 2 3 4 2 3 4 1 2)))(newline)
  34. (display (longestUniqum '(1 2 5 3 5 6 5 4 3)))(newline)
  35. (display (longestUniqum '(1 2 3 1 3 2)))(newline)  
  36.  
  37. (define (help n i)
  38.     (if (= i 1) 1
  39.         (+ (help n (- i 1))
  40.             (if (and (= 1 (mod i 2))  (= 0 (mod n i))  )
  41.                 i 0
  42.             )
  43.         )
  44.     )
  45. )
  46.  
  47. (define (odd-divisors n)
  48.     (help n n)
  49. )
  50.  
  51.  
  52. (display (odd-divisors 24))(newline)
  53. (display (odd-divisors 17))(newline)
  54. (display (odd-divisors 15))(newline)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement