Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.90 KB | None | 0 0
  1. ;finds me the number that was repeated the most
  2. (define (sameNum L)
  3.   (let ((greatestNum 0) (gCount 0))
  4.     (let recur ((count 0) (current '()) (myList L))
  5.       (cond
  6.         ((null? current) (recur 1 (car myList) (cdr myList)))
  7.         ((and (null? myList) (= gCount count)) (finish current count))
  8.         ((null? myList) (if (= 0 gCount) (finish current count) (finish greatestNum gCount)))
  9.         ((= current (car myList)) (recur (+ 1 count) (car myList) (cdr myList)))
  10.         ((or (< gCount count) (= gCount count)) (set! gCount count) (set! greatestNum current)
  11.                                                 (recur 1 (car myList) (cdr myList)))
  12.         (else (recur 1 (car myList) (cdr myList)))))))
  13.  
  14.  
  15. ;helper function
  16. ;(finish 2 5) -> '(2 2 2 2 2)
  17. (define (finish greatestNum gCount)
  18.   (let recur((b gCount))
  19.    (cond
  20.      ((= b 0) '())
  21.      (else (cons greatestNum (recur (- b 1)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement