-
-
Save dvanhorn/3c84d799be53c9632027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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