Skip to content

Commit

Permalink
Solve Sum of Consecutive Odd Numbers III in clojure
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Dec 11, 2024
1 parent 6b0f7a6 commit a4734b2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions solutions/beecrowd/1158/1158.clj
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a4734b2

Please sign in to comment.