-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09f4126
commit a9644b1
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |