Okay I want to count the number of times each [number] has appeared inside a list using Scheme.
How can I do that ? I also would like to store the counter of the given number and re-construct a new list.
For example I have the following list ((1 2)(2 5)(5 7)(7 8)(6 8)(4 6)(3 4)(1 3)(4 8))
I was thinking first flatten the list, and then set a counter for each number (don't know how to do it). And then reconstruct a new list corresponding to the original number. (this can be tricky ? I need to store a temporary variable ?)
Say from this example the number 1 appeared twice, number 2 appeared twice, number 3 twice etc... so I would like to recreate a new list to something like this:
(1 2) (2 2) (3 2) (4 3) (5 2) (7 2) (6 2) (8 3)
any idea how I can achieve this ?
Update:
I was thinking to implement an increment counter helper something like this ?
(define inc-counter
(let ((counter 0))
(lambda () (set! counter (+ counter 1)))))