Sha256: 58a2f11af4f112608096dbd69178ccbca24b7dd22fd8ac9de511df18200e4047

Contents?: true

Size: 769 Bytes

Versions: 396

Compression:

Stored size: 769 Bytes

Contents

(ns scrabble-score
  (:require [clojure.string :refer [split]]))

;; The letter values as shown in the README
(def ^:private letter-values
  {"AEIOULNRST" 1
   "DG"         2
   "BCMP"       3
   "FHVWY"      4
   "K"          5
   "JX"         8
   "QZ"        10})

;; A map from letter (as string) to score
(def ^:private letter->score
  (reduce-kv (fn [acc letters score]
               (-> (map str letters)
                   (zipmap (repeat score))
                   (->> (merge acc))))
             {} letter-values))

;; Defaults to 0 for non-alphabetic input
(defn score-letter [letter]
  (get letter->score (.toUpperCase (str letter)) 0))

(defn score-word [word]
  (reduce (fn [score letter]
            (+ score (score-letter letter)))
          0 word))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/scrabble-score/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/scrabble-score/src/example.clj