Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (increment-word hashmap words)
- (if (empty? words)
- hashmap
- (let ([word (car words)])
- (let ([count (hash-ref hashmap word 0)])
- (let ([hashmap-next (hash-set hashmap word (+ count 1))])
- (increment-word hashmap-next (cdr words)))))))
- (define (process-line hashmap line)
- (let ([words (string-split (string-downcase line))])
- (increment-word hashmap words)))
- (define (read-from-stdin)
- (define (read-from-stdin-it hashmap)
- (let ([line (read-line)])
- (if (eof-object? line)
- hashmap
- (read-from-stdin-it (process-line hashmap line)))))
- (let ([wc (hash)])
- (read-from-stdin-it wc)))
- (define sorted (sort (hash->list (read-from-stdin))
- >
- #:key cdr))
- (for ([pair sorted])
- (printf "~A ~A~%" (car pair) (cdr pair)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement