Guest User

Untitled

a guest
Dec 12th, 2019
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (define (moreFrequent l1 l2)
  2.   (cond  ((null? l1) l2)
  3.          ((null? l2) l1)
  4.          ((>= (length l1) (length l2)) l1)
  5.          (else l2)))
  6.  
  7. (define (mostFrequentList l)
  8.   (if (null? l) '()
  9.        (moreFrequent (filter (lambda (x) (= (car l) x)) l) (mostFrequentList (cdr l)))))
  10.  
  11. (define (mostFrequentNum l) (car (mostFrequentList l)))
  12.  
  13. (define (mostFrequent l)
  14.   (let ((mostFrequentInFirst (mostFrequentNum (car l))))
  15.   (if (all? (lambda (x) (= (mostFrequentNum x) mostFrequentInFirst)) l)
  16.       mostFrequentInFirst
  17.       0)))
RAW Paste Data