• + 0 comments

    Racket. It's a little bit unfriendly for racket to process strings I think.

    #lang racket
    (define (num-to-list-of-char x)
      (string->list (number->string x)))
    
    (define (compress l [c 1])
      (if (empty? (cdr l))
          (cons (car l) (if (= 1 c) (list) (num-to-list-of-char c)))
          (if (char=? (car l) (cadr l))
              (compress (cdr l) (+ c 1))
              (if (> c 1)
                  (cons (car l) (append (num-to-list-of-char c) (compress (cdr l))))
                  (cons (car l) (compress (cdr l)))))))
    
    (let ([q (read-line)])
      (display (list->string (compress (string->list q)))))