Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Population-count/Clojure/population-count.clj
Normal file
28
Task/Population-count/Clojure/population-count.clj
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(defn population-count [n]
|
||||
(Long/bitCount n)) ; use Java inter-op
|
||||
|
||||
(defn exp [n pow]
|
||||
(reduce * (repeat pow n)))
|
||||
|
||||
(defn evil? [n]
|
||||
(even? (population-count n)))
|
||||
|
||||
(defn odious? [n]
|
||||
(odd? (population-count n)))
|
||||
|
||||
;;
|
||||
;; Clojure's support for generating "lazily-evaluated" infinite sequences can
|
||||
;; be used to generate the requested output sets. We'll create some infinite
|
||||
;; sequences, and only as many items will be computed as are "pulled" by 'take'.
|
||||
;;
|
||||
(defn integers []
|
||||
(iterate inc 0))
|
||||
|
||||
(defn powers-of-n [n]
|
||||
(map #(exp n %) (integers)))
|
||||
|
||||
(defn evil-numbers []
|
||||
(filter evil? (integers)))
|
||||
|
||||
(defn odious-numbers []
|
||||
(filter odious? (integers)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue