A Proper Solution to Project Euler Problem Sixteen
Here's my solution to Project Euler problem sixteen, written in Clojure. I'm a bit offended by most of the solutions in the message thread because they require bignum support, which is basically a pathetically easy way to solve this problem.
(defn carry [coll]
(reverse
(loop [c coll extra 0 acc '()]
(if (nil? c)
(if (zero? extra) acc (cons 1 acc))
(let [v (+ extra (first c))]
(recur (next c) (int (/ v 10)) (cons (mod v 10) acc)))))))
(defn dbl [coll]
(carry (map (partial * 2) coll)))
(defn eul-16 [iters]
(reduce + 0
(loop [n 0 acc '(1)]
(if (= n iters)
acc
(recur (inc n) (dbl acc))))))
(eul-16 1000)