## Monday, August 15, 2011

### Numeral systems

Here is a function that can be used to evaluate any numeral:

(defn evaluate-numeral

(apply +
(map-indexed
(fn [i v]
(* v (Math/pow radix (- (dec (count numerals)) i))))
numerals)))

(= (evaluate-numeral '(1 0 1 0 1) 2)
21)


You can also evaluate the amount of digits needed for a number in any numeral system:

(defn digits-in-number