Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Josephus-problem/Clojure/josephus-problem.clj
Normal file
13
Task/Josephus-problem/Clojure/josephus-problem.clj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(defn rotate [n s] (lazy-cat (drop n s) (take n s)))
|
||||
|
||||
(defn josephus [n k]
|
||||
(letfn [(survivor [[ h & r :as l] k]
|
||||
(cond (empty? r) h
|
||||
:else (survivor (rest (rotate (dec k) l)) k)))]
|
||||
(survivor (range n) k)))
|
||||
|
||||
(let [n 41 k 3]
|
||||
(println (str "Given " n " prisoners in a circle numbered 1.." n
|
||||
", an executioner moving around the"))
|
||||
(println (str "circle " k " at a time will leave prisoner number "
|
||||
(inc (josephus n k)) " as the last survivor.")))
|
||||
Loading…
Add table
Add a link
Reference in a new issue