Skip to content

Instantly share code, notes, and snippets.

@spacemeowx2
Created April 15, 2019 05:42
Show Gist options
  • Save spacemeowx2/df7f8909871622b8da73733be9017151 to your computer and use it in GitHub Desktop.
Save spacemeowx2/df7f8909871622b8da73733be9017151 to your computer and use it in GitHub Desktop.
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