diff options
| author | Tyler Wardhaugh <twardhaugh@cap-rx.com> | 2021-10-23 00:11:24 -0700 |
|---|---|---|
| committer | Tyler Wardhaugh <twardhaugh@cap-rx.com> | 2021-10-23 00:11:24 -0700 |
| commit | a40b2f9808880cef125c9c5d94258f171f977f3f (patch) | |
| tree | 1ca6f19570721574a4f66a51e7c72c14c07887b5 | |
| parent | 79db9f54e32c0f4394c6133f0526180bde54a3e7 (diff) | |
| download | perlweeklychallenge-club-a40b2f9808880cef125c9c5d94258f171f977f3f.tar.gz perlweeklychallenge-club-a40b2f9808880cef125c9c5d94258f171f977f3f.tar.bz2 perlweeklychallenge-club-a40b2f9808880cef125c9c5d94258f171f977f3f.zip | |
improve Task 2 & remove unnecessary map
We can use the Character/digit static function with a radix of 36 to
avoid having to create a character->number map and performing lookups.
| -rw-r--r-- | challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj b/challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj index 9018ee2787..e905cae9a7 100644 --- a/challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj +++ b/challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj @@ -5,13 +5,11 @@ ;;; (def DEFAULT-INPUT ["2936921"]) -(let [weights [1 3 1 7 3 9] - c->n (->> "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" - (into {} (map-indexed #(vector %2 %1))))] +(let [weights [1 3 1 7 3 9]] (defn check-digit [coll] (let [source (map vector coll weights) - xf (map (fn [[c w]] (* (c->n c) w))) + xf (map (fn [[c w]] (* (Character/digit c 36) w))) sum (transduce xf + source)] (mod (- 10 (mod sum 10)) 10)))) |
