ryoakg
12/22/2012 - 4:17 AM

Project Euler Problem 16 solution in Clojure

Project Euler Problem 16 solution in Clojure

;;;; Project Euler Problem 16 solution
;;;; http://projecteuler.net/problem=16

(use 'clojure.test)
(import 'java.math.BigInteger)

;; Character/digit usage from: https://gist.github.com/4276901
(def solve
  (comp (partial apply +)
        (partial map #(Character/digit ^char % 10))
        str
        #(. (BigInteger. "2") pow %)
        ;; no reflection warnings at this method call. really?
        ;; cf. #(. % pow %2) => reflection warning "call to pow can't be resolved."
        ))

(is (= 26 (solve 15)))
(is (= 1366 (solve 1000)))