slovo/benchmarks/vec-string-eq-loop/clojure/vec_string_eq_loop.clj
2026-05-22 08:38:43 +02:00

35 lines
1.0 KiB
Clojure

(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(def loop-count 1000000)
(def expected-checksum 4600001)
(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 configured-target []
(or (first *command-line-args*) "omega"))
(defn vec-string-eq-loop [limit target]
(let [words ["alpha" "omega" "delta" "omega" "sigma"]]
(loop [i 0
acc 1]
(if (< i limit)
(let [current (nth words (rem i 5))
next (if (= ^String current ^String target)
(+ acc 7)
(+ acc 3))
bounded (if (> next 1000000000)
(- next 1000000000)
next)]
(recur (inc i) bounded))
acc))))
(let [result (vec-string-eq-loop (configured-loop-count) (configured-target))]
(println result)
(System/exit (if (= result expected-checksum) 0 1)))