Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (add-multiplicity l e)
- (if (null? l)
- (list (cons e 1))
- (if (equal? (car (car l)) e)
- (cons (cons e (+ (cdr (car l)) 1)) (cdr l))
- (cons (car l) (add-multiplicity (cdr l) e))
- )
- )
- )
- (define (multiplicitylst lst)
- (letrec
- ((walk (lambda (list mul)
- (if (null? list)
- mul
- (walk (cdr list) (add-multiplicity mul (car list)))
- )
- )
- ))
- (walk lst '())
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement