Skip to content

Instantly share code, notes, and snippets.

@nickmain
Created October 24, 2014 22:30
Show Gist options
  • Save nickmain/0f33d1effe5bf3c9ee4a to your computer and use it in GitHub Desktop.
Save nickmain/0f33d1effe5bf3c9ee4a to your computer and use it in GitHub Desktop.
#lang racket
(define (run-length n)
(let ([run-char #f]
[run-len 0])
(λ(c)
(if (equal? c run-char)
(set! run-len (+ run-len 1))
(begin (set! run-len 1)
(set! run-char c)))
(<= run-len n))))
(define (remove-extra-consecutive s i)
(list->string
(filter (run-length i)
(string->list s))))
(remove-extra-consecutive "aaab" 2)
(remove-extra-consecutive "aabb" 1)
(remove-extra-consecutive "aabbaa" 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment