Statement: Sind the longest chain of character and return it.
Ex: input: '(1 2 2 3 3 3 4 4 4 4 5 6 )
ouput: '(4 4 4 4)
Problem: I can manage to identify all the different groups in the list and compare them but can't get the function to return the right subset list. It only returns the last group analyzed.
code:
(define finalL (list))
(define (sameNum liste)
(if (or (null? liste) (null? (cdr liste)))
;; true
'()
;; false
(let ([lcdr (sameNum (cdr liste))])
(if (eqv? (car liste) (car(cdr liste)) )
;; true
(if (= (length liste) 2)
;; true
(cons (car liste) (cons (car(cdr liste)) lcdr))
;; false
(if (or (not(eqv? (car(cdr liste)) (car(cdr (cdr liste))) )) (null? (cdr liste)) )
(cons (car liste) (cons (car(cdr liste)) lcdr)) ;true
(cons (car liste) lcdr))) ; false
;; false
(if (let ((x (length lcdr)) (y (length finalL))) (< x y))
;; true
(crushL finalL lcdr)
;; false
finalL)))))
;; crush L1 and replace by value of L2
(define (crushL L1 L2)
(if (null? L1)
;; true
(cons L2 L1)
;; false
(crushL (cdr L1) L2)))