Project Euler Problem 20

Ivar Thorson bio photo By Ivar Thorson

Problem 20 turned out to be yet another ridiculously simple problem for Clojure. Here’s how to sum the digits in 100 factorial:

(defn factorial  [n] (reduce * (range 2 (inc n))))
(defn sum-digits [s] (reduce + (map #(Integer/parseInt (str %)) s)))
(defn euler-20   []  (sum-digits (str (factorial 100))))

(euler-20)