File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
src/math/stats/quantquestions/what_are_the_odds Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ (ns math.stats.quantquestions.what-are-the-odds.five-pirates-treasure )
2+
3+ (def pirates
4+ [" Green Boots" " Red Rackham" " Blue Thunder" " Black Beard" " Tim" ])
5+
6+ ; ; With only one pirate, they get all the booty
7+ ; ; * Green Boots: 100
8+
9+ ; ; With 2 pirates, whoever proposes the split gets all the booty
10+ ; ; * Red Rackham 100
11+ ; ; * Green Boots 0
12+
13+ ; ; With 3 pirates, the pirate who would miss out in the next round is incentivised by 1 coin
14+ ; ; * Blue Thunder 99
15+ ; ; * Red Rackham 0
16+ ; ; * Green Boots 1
17+
18+ ; ; With 4 pirates, 1 vote needed, the pirate who would miss out is incentivised by 1 coin
19+ ; ; * Black Beard 99
20+ ; ; * Blue Thunder 0
21+ ; ; * Red Rackham 1
22+ ; ; * Green Boots 0
23+
24+ ; ; With 5 pirates, 2 votes needed, the 2 pirates who would miss out in the next round get a coin each
25+ ; ; * Tim 98
26+ ; ; * Black Beard 0
27+ ; ; * Blue Thunder 1
28+ ; ; * Red Rackham 0
29+ ; ; * Green Boots 1
30+
31+ ; ; Probably you can spot a pattern emerging here...
32+
33+ (defn split [coins pirates]
34+ (let [n (count pirates)]
35+ (-> (mapv vector
36+ (reverse pirates)
37+ (cycle (if (odd? n) [1 0 ] [0 1 ])))
38+ (assoc-in [0 1 ] (- coins (/ (if (odd? n) (dec n) n) 2 ))))))
39+
40+ (split 100 pirates)
41+
42+ ^:kind/table
43+ (split 100 pirates)
You can’t perform that action at this time.
0 commit comments