Not very interesting solution, since I use int/string conversions. As a clojure newcomer it feels a bit weird using the Java String API, just because you know its there. Writing functions to wrap the Java String API is probably not idiomatic Clojure, but I think it might be nice to wrap them in macros one day, to make the substring calls look a bit more Clojure-ish.
Solves in about 20msec.
(def bignumber "73167176531330624919......") ;; elided
(defn- calc-offsets []
(range 0 (- 1000 5)))
(defn- five-digit-list [bigstring offset]
(let [substr (.substring bigstring offset (+ 5 offset))]
(map #(Integer/parseInt (str %)) substr)))
(defn- five-digit-lists [bigstring]
(map #(five-digit-list bigstring %) (calc-offsets)))
(defn solve []
(apply max (map #(apply * %) (five-digit-lists bignumber))))
Org-mode PDF export failure
-
Having replaced my laptop due to a tea related accident, I am finding a few
things that I need to reconfigure. Org exports are one of them. On my new
fedor...
14 years ago
No comments:
Post a Comment