From a40b2f9808880cef125c9c5d94258f171f977f3f Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 23 Oct 2021 00:11:24 -0700 Subject: 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. --- challenge-135/tyler-wardhaugh/clojure/src/tw/weekly/c135/t2.clj | 6 ++---- 1 file 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)))) -- cgit