30 lines
791 B
Clojure
30 lines
791 B
Clojure
(set! *warn-on-reflection* true)
|
|
(set! *unchecked-math* :warn-on-boxed)
|
|
|
|
(def loop-count 1000000)
|
|
(def expected-checksum 3875007)
|
|
(def digits [3 1 4 1 5 9 2 6])
|
|
|
|
(defn configured-loop-count []
|
|
(try
|
|
(let [line (read-line)
|
|
value (Integer/parseInt (.trim ^String line))]
|
|
(if (pos? value) value loop-count))
|
|
(catch Exception _
|
|
loop-count)))
|
|
|
|
(defn array-index-loop [limit]
|
|
(loop [i 0
|
|
acc 7]
|
|
(if (< i limit)
|
|
(let [next (+ acc (nth digits (rem i 8)))
|
|
bounded (if (> next 1000000000)
|
|
(- next 1000000000)
|
|
next)]
|
|
(recur (inc i) bounded))
|
|
acc)))
|
|
|
|
(let [result (array-index-loop (configured-loop-count))]
|
|
(println result)
|
|
(System/exit (if (= result expected-checksum) 0 1)))
|