-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem-22.scm
More file actions
24 lines (23 loc) · 831 Bytes
/
Copy pathProblem-22.scm
File metadata and controls
24 lines (23 loc) · 831 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
(load "auxiliaries.scm")
(define names.txt (open-input-file "p022_names.txt"))
(read-char names.txt)
(define (list-of-names names-port result)
(let* ((delimiter (char-set #\"))
(name (read-string delimiter names-port)))
(if (eof-object? name)
result
(begin
(read-char names.txt)
(read-char names.txt)
(read-char names.txt)
(list-of-names names-port (cons name result))))))
(define sorted-names-list
(sort (list-of-names names.txt '()) string<?))
(define (sum-of-chars str)
(accumulate + 0 (map (lambda (char) (- (char->integer char) 96))
(string->list (string-downcase str)))))
(define (p22)
(accumulate + 0
(map (lambda (name-value place-value) (* name-value place-value))
(map sum-of-chars sorted-names-list)
(enumerate-interval 1 (length sorted-names-list)))))