Skip to content

Instantly share code, notes, and snippets.

@dvanhorn

dvanhorn/2.rkt Secret

Created August 27, 2011 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvanhorn/3c84d799be53c9632027 to your computer and use it in GitHub Desktop.
Save dvanhorn/3c84d799be53c9632027 to your computer and use it in GitHub Desktop.
#lang racket
(define str
;; put large string from src code here.
#<<HERE
...
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))]
(values
(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))
p)
< #:key cddr)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment