Anonymous user
Ethiopian multiplication: Difference between revisions
clojure impl
(clojure impl) |
|||
Line 424:
...equals 578
</pre>
=={{header|Clojure}}==
<lang clojure>
(defn halve [n]
(bit-shift-right n 1))
(defn twice [n] ; 'double' is taken
(bit-shift-left n 1))
(defn even [n] ; 'even?' is the standard fn
(zero? (bit-and n 1)))
(defn emult [x y]
(reduce +
(map second
(filter #(not (even (first %))) ; a.k.a. 'odd?'
(take-while #(pos? (first %))
(map vector
(iterate halve x)
(iterate twice y)))))))
</lang>
=={{header|Common Lisp}}==
|