Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (first-uniq chars)
- (when (empty? chars)
- (raise "There are no unique letters"))
- (let ([c (first chars)])
- (if (memq c (rest chars)) ; MEMQ is like MEMBER with EQ?
- (first-uniq (remq* (list c) chars)) ; N.B the tail-recursion here
- c)))
- (require rackunit)
- (check-equal? (first-uniq (string->list "aabcbcdeef"))
- #\d)
- (check-equal? (first-uniq (string->list "faabcbcdeef"))
- #\d)
- (check-equal? (first-uniq (string->list "aabcbcdeefd"))
- #\f)
Add Comment
Please, Sign In to add comment