Skip to content

Commit

Permalink
Solve Power Crisis in clojure
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Oct 22, 2024
1 parent 09f4126 commit a9644b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions solutions/beecrowd/1031/1031.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(ns main)

(defn josephus [n k]
(loop [current-n 2
result 1]
(if
(> current-n n)
result
(recur (inc current-n)
(-> result
(+ k)
dec
(mod current-n)
(inc))))))

(defn calculate [n]
(loop [m 1]
(if (= 12 (josephus (dec n) m))
m
(recur (inc m)))))

(defn main []
(loop [line (Integer/parseInt (read-line))]
(printf "%d%n" (calculate line))
(let [line' (Integer/parseInt (read-line))]
(when (not= line' 0)
(recur line')))))

(main)

0 comments on commit a9644b1

Please sign in to comment.