secret
Created

  • Download Gist
2.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#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)))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.