Skip to content

Commit 1aec60d

Browse files
Merge pull request #23 from timothypratley/main
add five-pirates-treasure
2 parents 86e298d + 3db31f8 commit 1aec60d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
^{:kindly/hide-code true
2+
:clay {:title "Five Pirates Treasure Splitting"
3+
:quarto {:type :post
4+
:author [:timothypratley]
5+
:date "2025-06-18"
6+
:category :math
7+
:tags [:probability :stats]
8+
:keywords [:quantquestions]}}}
9+
(ns math.stats.quantquestions.what-are-the-odds.five-pirates-treasure)
10+
11+
(def pirates
12+
["Green Boots" "Red Rackham" "Blue Thunder" "Black Beard" "Tim"])
13+
14+
;; With only one pirate, they get all the booty
15+
;; * Green Boots: 100
16+
17+
;; With 2 pirates, whoever proposes the split gets all the booty
18+
;; * Red Rackham 100
19+
;; * Green Boots 0
20+
21+
;; With 3 pirates, the pirate who would miss out in the next round is incentivised by 1 coin
22+
;; * Blue Thunder 99
23+
;; * Red Rackham 0
24+
;; * Green Boots 1
25+
26+
;; With 4 pirates, 1 vote needed, the pirate who would miss out is incentivised by 1 coin
27+
;; * Black Beard 99
28+
;; * Blue Thunder 0
29+
;; * Red Rackham 1
30+
;; * Green Boots 0
31+
32+
;; With 5 pirates, 2 votes needed, the 2 pirates who would miss out in the next round get a coin each
33+
;; * Tim 98
34+
;; * Black Beard 0
35+
;; * Blue Thunder 1
36+
;; * Red Rackham 0
37+
;; * Green Boots 1
38+
39+
;; Probably you can spot a pattern emerging here...
40+
41+
(defn split [coins pirates]
42+
(let [n (count pirates)]
43+
(-> (mapv vector
44+
(reverse pirates)
45+
(cycle (if (odd? n) [1 0] [0 1])))
46+
(assoc-in [0 1] (- coins (/ (if (odd? n) (dec n) n) 2))))))
47+
48+
(split 100 pirates)
49+
50+
^:kind/table
51+
(split 100 pirates)

0 commit comments

Comments
 (0)