We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Help counting duplicate items in list with Scheme

TechLearnerCA
on
Medium Priority
2,159 Views
Last Modified: 2012-05-11
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

Comment
Watch Question

CEO/Programmer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.