what is a more efficient way to accomplish this in clojure:
(defn ones ([n] (ones n 1 1)) ([n i res] (if (< i n) (recur n (inc i) (bit-set res i)) res)))
preferably it should still "do the right thing" when it comes to numerical type.
what is a more efficient way to accomplish this in clojure:
(defn ones ([n] (ones n 1 1)) ([n i res] (if (< i n) (recur n (inc i) (bit-set res i)) res)))
preferably it should still "do the right thing" when it comes to numerical type.
Why not take 2^(X-1) (by setting only the Xth bit) and then subtract 1?