Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(defn solves-for? [sailors initial-coconut-count]
|
||||
(with-local-vars [coconuts initial-coconut-count, hidings 0]
|
||||
(while (and (> @coconuts sailors) (= (mod @coconuts sailors) 1)
|
||||
(var-set coconuts (/ (* (dec @coconuts) (dec sailors)) sailors))
|
||||
(var-set hidings (inc @hidings)))
|
||||
(and (zero? (mod @coconuts sailors)) (= @hidings sailors))))
|
||||
|
||||
(doseq [sailors (range 5 7)]
|
||||
(let [start (first (filter (partial solves-for? sailors) (range)))]
|
||||
(println (str sailors " sailors start with " start " coconuts:"))
|
||||
(with-local-vars [coconuts start]
|
||||
(doseq [sailor (range sailors)]
|
||||
(let [hidden (/ (dec @coconuts) sailors)]
|
||||
(var-set coconuts (/ (* (dec @coconuts) (dec sailors)) sailors))
|
||||
(println (str "\tSailor " (inc sailor) " hides " hidden " coconuts and gives 1 to the monkey, leaving " @coconuts "."))))
|
||||
(println
|
||||
(str "\tIn the morning, each sailor gets another " (/ @coconuts sailors) " coconuts."))
|
||||
(println "\tThe monkey gets no more.\n"))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue