Created
April 15, 2019 05:42
-
-
Save spacemeowx2/df7f8909871622b8da73733be9017151 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const groupCount = 5 | |
function sim() { | |
let score = {} | |
for (let i = 0; i < groupCount; i++) { | |
score[i] = 0 | |
} | |
for (let i = 0; i < groupCount - 1; i++) { | |
for (let j = i + 1; j < groupCount; j++) { | |
const win1 = Math.random() < 0.5 | |
const isKO = Math.random() < 0.01 | |
const winS = isKO ? 3 : 2 | |
const lostS = -1 | |
if (win1) { | |
score[i] += winS // win | |
score[j] += lostS // lost | |
} else { | |
score[j] += winS // win | |
score[i] += lostS // lost | |
} | |
} | |
} | |
const ss = [...Object.values(score)] | |
let max = 0 | |
const repeatTimes = ss.map(i => [i, ss.filter(j => j === i).length]) | |
for (let [s, r] of repeatTimes) { | |
max = Math.max(r, max) | |
} | |
return max | |
} | |
function test() { | |
const round = 1000000 | |
let total = {} | |
for (let c = 0; c < round; c++) { | |
const r = sim() | |
total[r] = (total[r] || 0) + 1 | |
} | |
let result = {} | |
for (let i of Object.keys(total)) { | |
result[i] = total[i] / round | |
} | |
console.log(result) | |
} | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment