Link to home
Start Free TrialLog in
Avatar of TechLearnerCA
TechLearnerCA

asked on

Help counting duplicate items in list with Scheme

Hi I am given a list( a b a a a a c c c) and I need to return ((1 a)(1 b)(3 a)(2c))

I am stuck and not sure how to make this work.
Here is the code I have so far:
(define (countrepeat lst)
  (cond
    ((null? lst) '())
    ((null? (cdr lst)) (list(car lst)))
    
    ((equal? (car lst)(car(cdr lst))) (cons(list(car lst(count(car lst))))(countrepeat(cdr lst))))
    
    (else ((list(1 car lst))(countrepeat(cdr lst))))
    
    ))

(define (count lst)
  (cond
    ((null? list) 0)
    
    
    ((=(car lst)(car(cdr lst)))(+1 (count(cdr lst))))
    ))

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.