From a9644b13aa5b3619fc7d0da37000bb8d373d0214 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Tue, 22 Oct 2024 20:02:40 -0300 Subject: [PATCH] Solve Power Crisis in clojure --- solutions/beecrowd/1031/1031.clj | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 solutions/beecrowd/1031/1031.clj diff --git a/solutions/beecrowd/1031/1031.clj b/solutions/beecrowd/1031/1031.clj new file mode 100644 index 00000000..b8f1a774 --- /dev/null +++ b/solutions/beecrowd/1031/1031.clj @@ -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)