Last active
December 19, 2022 13:08
-
-
Save kbjarkefur/7441227c6c722cdc6c2be1e61b36e826 to your computer and use it in GitHub Desktop.
pool-tiebreaker
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
qui { | |
* Fill in the entry fee and number of entried | |
local entry_fee = 5 | |
local entries = 16 | |
* rounding to take care of some floating point math issue | |
local pool = round(`entry_fee' * `entries',1) | |
* Fill in the how many people placed 1st, 2nd, 3rd | |
local ties_1st 1 | |
local ties_2nd 1 | |
local ties_3rd 3 | |
* If 3 people or more placed 1st, then no money to 2nd or 3rd | |
if `ties_1st' >= 3 { | |
local tot_price_1st = `pool' | |
local tot_price_2nd = 0 | |
local tot_price_3rd = 0 | |
} | |
else { | |
* If 3 people or more placed 1st and 2nd, then no money to 3rd | |
if `ties_1st' + `ties_2nd' >= 3 { | |
local tot_price_1st = 0.8 * `pool' | |
local tot_price_2nd = 0.2 * `pool' | |
local tot_price_3rd = 0 | |
} | |
else { | |
* All 3rd placers gets their money back | |
local tot_price_3rd = `entry_fee' * `ties_3rd' | |
* First placers gets 80% of remaining pool (rounded down) | |
local tot_price_1st = floor(0.8 * (`pool' - `tot_price_3rd')) | |
* Second placers gets the rest | |
local tot_price_2nd = `pool' - `tot_price_1st' - `tot_price_3rd' | |
} | |
} | |
* Test that prices equals pool - rounding to take care of some floating point math issue | |
assert (`pool' - round(`tot_price_1st' + `tot_price_2nd' + `tot_price_3rd',1)) == 0 | |
* Calculate what each person in 1st, 2nd and 3rd place got. | |
foreach plc in 1st 2nd 3rd { | |
local price_`plc' = `tot_price_`plc'' / `ties_`plc'' | |
noi di "People placing `plc' recieves: `price_`plc''" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment