Create a gist now

Instantly share code, notes, and snippets.

@dvanhorn /2.rkt Secret
Created Aug 27, 2011

#lang racket
(define str
;; put large string from src code here.
;; h = [Hash Char (Pair Nat Nat)]
;; where (Pair Nat Nat) represents occurrence count and last occurrence position.
(define-values (h _)
(for/fold [(h (hash)) (i 0)]
[(c (in-string str))]
(hash-update h c (λ (p) (cons (add1 (car p)) i)) (cons 0 i))
(add1 i))))
(apply string
(map car (sort (for/list ([p (in-hash-pairs h)]
#:when (< (cadr p) 10))
< #:key cddr)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment