InfoTechEE
asked on
Scheme recursion question (part 2)
I need to write a function that accepts a single string (a b a a a c c)
that counts the number of repeated occurrences, yielding ((1 a) (1 b) (3 a) (2 c)).
that counts the number of repeated occurrences, yielding ((1 a) (1 b) (3 a) (2 c)).
ASKER
Yes, but I'm not sure what each function is suppose to do.
Here's what I'm understanding thus far:
(count_dups lst)
no recursion happens here...just calls the helper function
not sure what to pass to the helper function here
(count_dups count lst)
recursion occurs in this function, but under what circumstances?
Here's what I'm understanding thus far:
(count_dups lst)
no recursion happens here...just calls the helper function
not sure what to pass to the helper function here
(count_dups count lst)
recursion occurs in this function, but under what circumstances?
(count_dups lst)
no recursion happens here...just calls the helper function
Right
not sure what to pass to the helper function here
Well, the helper function needs a count so pass it whatever the count should start as (0 or 1 depending on how you do the rest of it)
(count_dups count lst)
recursion occurs in this function, but under what circumstances?
I would do it just like the other two where you consume one character every time and keep making recursive calls 'til the string runs out.
So you have a count and a string and you compare the first two characters. Assuming count always equals the current count of the duplicates,
If they match, what should you do?
If they don't match, then what?
no recursion happens here...just calls the helper function
Right
not sure what to pass to the helper function here
Well, the helper function needs a count so pass it whatever the count should start as (0 or 1 depending on how you do the rest of it)
(count_dups count lst)
recursion occurs in this function, but under what circumstances?
I would do it just like the other two where you consume one character every time and keep making recursive calls 'til the string runs out.
So you have a count and a string and you compare the first two characters. Assuming count always equals the current count of the duplicates,
If they match, what should you do?
If they don't match, then what?
ASKER
I'm thinking if 1st and 2nd element match, I need to increment the counter.
If they dont match, just output a 1 and car(lst)?
If they dont match, just output a 1 and car(lst)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
InfoTechEE
can you show me how you solved this problem?
thanks!
can you show me how you solved this problem?
thanks!
TechLearner, all the information is there to solve it. What else could you possibly need? Are you just looking to have someone give you the full code because you have the same assignment?
What you should do is hit 'ask a related question' and post your own question asking for clarification. Don't just ask for an answer though. Since this is an academic style problem, we are instructed to help you solve it yourself. So include the code you have so far and what it is and isn't doing that it shouldn't or should be.
What you should do is hit 'ask a related question' and post your own question asking for clarification. Don't just ask for an answer though. Since this is an academic style problem, we are instructed to help you solve it yourself. So include the code you have so far and what it is and isn't doing that it shouldn't or should be.
Hi TommySzalapski, I am not looking for someone do my work for me.
I posted a question: https://www.experts-exchange.com/questions/26974518/Help-counting-duplicate-items-in-list-with-Scheme.html
and I have not gotten any responses. Could you look at my question, please?
I posted a question: https://www.experts-exchange.com/questions/26974518/Help-counting-duplicate-items-in-list-with-Scheme.html
and I have not gotten any responses. Could you look at my question, please?
I tried to implement what was discussed above and I have some errors:
procedure application: expected procedure, given: 1 (no arguments)
procedure application: expected procedure, given: 1 (no arguments)
(define (countrepeat lst)
(count((1) (lst)))
)
(define (count s lst)
(cond
((null? list) '())
((null? (cdr lst)) '())
((equal? (car lst)(car(cdr lst))) (count(+1 cdr lst)))
(else (list s(list(car lst))))
))
Helper functions work like this:
You call the main function which calls the helper function which calls itself. So the main function isn't recursive in itself. You need this because you need to pass an integer for the count. Then you just need to compare car and car(cdr) and pass cdr to the helper function for the recursion.
So you'll have count_dups lst which will call count_dupsH count lst
Does that make sense?