From a4734b2ceb35cb57bf7b462793ecd639a492b1b5 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Tue, 10 Dec 2024 21:29:07 -0300 Subject: [PATCH] Solve Sum of Consecutive Odd Numbers III in clojure --- solutions/beecrowd/1158/1158.clj | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/beecrowd/1158/1158.clj diff --git a/solutions/beecrowd/1158/1158.clj b/solutions/beecrowd/1158/1158.clj new file mode 100644 index 00000000..7880cfe0 --- /dev/null +++ b/solutions/beecrowd/1158/1158.clj @@ -0,0 +1,18 @@ +(ns main + (:require [clojure.string :as str])) + +(defn sum-odd-number [start quantity] + (->> (iterate inc start) + (filter odd?) + (take quantity) + (reduce +))) + +(defn main [] + (loop [n (Integer/parseInt (read-line))] + (when (> n 0) + (let [[x y] (->> (str/split (read-line) #" ") + (map #(Integer/parseInt %)))] + (println (sum-odd-number x y)) + (recur (dec n)))))) + +(main)