~willvaughn/kata

436a03d72d8443373f9ea46502c5f1b8cea41012 — William Vaughn 1 year, 5 months ago 4f4f91d
codewars bit-counting
A codewars/src/clj/org/willvaughn/codewars/bit_counting.clj => codewars/src/clj/org/willvaughn/codewars/bit_counting.clj +7 -0
@@ 0,0 1,7 @@
(ns org.willvaughn.codewars.bit-counting)

(defn count-bits [n]
  (->> n
       Integer/toBinaryString
       (map #(Character/digit % 10))
       (reduce +)))

A codewars/test/clj/org/willvaughn/codewars/bit_counting_test.clj => codewars/test/clj/org/willvaughn/codewars/bit_counting_test.clj +17 -0
@@ 0,0 1,17 @@
(ns org.willvaughn.codewars.bit-counting-test
  (:require [clojure.test :refer :all]
            [org.willvaughn.codewars.bit-counting :refer [count-bits]]))

(deftest sample-tests
  (testing "0"
    (is (= 0 (count-bits 0))))
  (testing "1"
    (is (= 1 (count-bits 1))))
  (testing "10"
    (is (= 2 (count-bits 10))))
  (testing "14"
    (is (= 3 (count-bits 14))))
  (testing "30"
    (is (= 4 (count-bits 30))))
  (testing "1234"
    (is (= 5 (count-bits 1234)))))