sorting etc
parent
18044c5cd4
commit
64a404fa30
@ -0,0 +1,75 @@
|
||||
#lang debug racket
|
||||
(require racket/dict)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define letter-scores
|
||||
'((A 4 4)
|
||||
(B 1 3)
|
||||
(C 2 3)
|
||||
(D 1 2)
|
||||
(E 1 3)
|
||||
(F 1 3)
|
||||
(G 2 3)
|
||||
(H 1 1)
|
||||
(I 1 1)
|
||||
(J 3 1)
|
||||
(K 1 3)
|
||||
(L 1 4)
|
||||
(M 1 1)
|
||||
(N 1 1)
|
||||
(O 2 2)
|
||||
(P 1 3)
|
||||
(Q 2 2)
|
||||
(R 1 3)
|
||||
(S 3 3)
|
||||
(T 4 4)
|
||||
(U 1 1)
|
||||
(V 4 4)
|
||||
(W 4 4)
|
||||
(X 3 3)
|
||||
(Y 4 4)
|
||||
(Z 3 3)
|
||||
(a 3 3)
|
||||
(b 1 2)
|
||||
(c 2 3)
|
||||
(d 2 1)
|
||||
(e 2 3)
|
||||
(f 3 3)
|
||||
(g 3 3)
|
||||
(h 1 1)
|
||||
(i 1.5 1.5)
|
||||
(j 3 1)
|
||||
(k 1 3)
|
||||
(l 1.5 1.5)
|
||||
(m 1 1)
|
||||
(n 1 1)
|
||||
(o 2 2)
|
||||
(p 1 2)
|
||||
(q 2 1)
|
||||
(r 1 3)
|
||||
(s 3 3)
|
||||
(t 3 3)
|
||||
(u 1 1)
|
||||
(v 4 4)
|
||||
(w 4 4)
|
||||
(x 3 3)
|
||||
(y 4 4)
|
||||
(z 3 3)))
|
||||
|
||||
(define left-score-table
|
||||
(for/hasheqv ([(letter scores) (in-dict letter-scores)])
|
||||
(values (car (string->list (symbol->string letter))) (car scores))))
|
||||
|
||||
(define right-score-table
|
||||
(for/hasheqv ([(letter scores) (in-dict letter-scores)])
|
||||
(values (car (string->list (symbol->string letter))) (cadr scores))))
|
||||
|
||||
|
||||
(define (kernscore word)
|
||||
(define cs (string->list word))
|
||||
(/ (for/sum ([left-c (in-list cs)]
|
||||
[right-c (in-list (cdr cs))])
|
||||
(* (hash-ref right-score-table left-c)
|
||||
(hash-ref left-score-table right-c)))
|
||||
(length cs)))
|
||||
|
Loading…
Reference in New Issue