-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path22.rkt
More file actions
24 lines (19 loc) · 701 Bytes
/
22.rkt
File metadata and controls
24 lines (19 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#lang racket
(require srfi/26
rackunit
(file "read-words.ss")
(only-in mzlib/etc this-expression-source-directory))
(define (string->numbers s)
(define base (sub1 (char->integer #\A)))
(map ((curryr -) base) (map char->integer (string->list s))))
(define (name->sum n)
(apply + (string->numbers n)))
(check-equal? (name->sum "COLIN") 53)
(for/fold ([sum 0])
([(name index) (in-indexed (sort (read-words-from
(build-path
(this-expression-source-directory)
"22.txt")) string<?))])
(+ sum
(* (add1 index)
(name->sum name))))