diff --git a/trinary/example.clj b/trinary/example.clj deleted file mode 100644 index 3c7aec8e..00000000 --- a/trinary/example.clj +++ /dev/null @@ -1,15 +0,0 @@ -(ns trinary) - -(defn- num->digits [num] - (->> num - (map str) - (map read-string))) - -(defn to-decimal - [num] - (if (re-seq #"^[0-2]+$" num) - (->> num num->digits reverse - (map-indexed - (fn [place digit] (* digit (reduce * (repeat place 3))))) - (apply +)) - 0)) \ No newline at end of file diff --git a/trinary/project.clj b/trinary/project.clj index f479ffbc..bc273309 100644 --- a/trinary/project.clj +++ b/trinary/project.clj @@ -1,6 +1,4 @@ (defproject trinary "0.1.0-SNAPSHOT" :description "trinary exercise." :url "https://github.com/exercism/xclojure/tree/master/trinary" - :source-paths [""] - :test-paths [""] :dependencies [[org.clojure/clojure "1.7.0"]]) diff --git a/trinary/src/example.clj b/trinary/src/example.clj new file mode 100644 index 00000000..636068a3 --- /dev/null +++ b/trinary/src/example.clj @@ -0,0 +1,10 @@ +(ns trinary) + +(defn to-decimal [num] + (loop [sum 0, num num] + (if (empty? num) + sum + (let [diff (.compareTo (first num) \0)] + (if (<= 0 diff 2) + (recur (+ (* sum 3) diff) (next num)) + 0))))) diff --git a/trinary/trinary_test.clj b/trinary/test/trinary_test.clj similarity index 88% rename from trinary/trinary_test.clj rename to trinary/test/trinary_test.clj index 7f3ef7bd..9822bb35 100644 --- a/trinary/trinary_test.clj +++ b/trinary/test/trinary_test.clj @@ -1,6 +1,6 @@ (ns trinary-test - (:require [clojure.test :refer :all] - [trinary :refer :all])) + (:require [clojure.test :refer [deftest is testing]] + [trinary :refer [to-decimal]])) (deftest trinary-1-is-decimal-1 (testing "1 should still be 1" @@ -40,4 +40,4 @@ (deftest invalid-input-with-digits-is-decimal-0 (testing "0a1b2c should be 0" - (is (= 0 (to-decimal "0a1b2c"))))) \ No newline at end of file + (is (= 0 (to-decimal "0a1b2c")))))