Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;finds me the number that was repeated the most
- (define (sameNum L)
- (let ((greatestNum 0) (gCount 0))
- (let recur ((count 0) (current '()) (myList L))
- (cond
- ((null? current) (recur 1 (car myList) (cdr myList)))
- ((and (null? myList) (= gCount count)) (finish current count))
- ((null? myList) (if (= 0 gCount) (finish current count) (finish greatestNum gCount)))
- ((= current (car myList)) (recur (+ 1 count) (car myList) (cdr myList)))
- ((or (< gCount count) (= gCount count)) (set! gCount count) (set! greatestNum current)
- (recur 1 (car myList) (cdr myList)))
- (else (recur 1 (car myList) (cdr myList)))))))
- ;helper function
- ;(finish 2 5) -> '(2 2 2 2 2)
- (define (finish greatestNum gCount)
- (let recur((b gCount))
- (cond
- ((= b 0) '())
- (else (cons greatestNum (recur (- b 1)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement