Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function randomInArray(arr) {
- return arr[Math.floor(Math.random() * arr.length)]
- }
- function oddsOfTopThree(rerolls) {
- let count = 0
- const scarabs = [...Array(16).keys()].map((i) => i + 1) // 1-16
- for (let i = 0; i < rerolls; i++) {
- const scarab = randomInArray(scarabs)
- if (scarab > scarabs.length - 3) count++
- }
- return count / rerolls
- }
- function main() {
- const initialScarabValue = 6
- const expectedAvgValue = 42
- const rerollCost = 1
- const rerolls = 1000
- const avgRerolls = oddsOfTopThree(rerolls)
- console.log(`Statisstics is based on ${rerolls} rerolls`)
- console.log(`Average rerolls per scarab ${Math.floor(1 / avgRerolls)}c`)
- const avgRerollCost = (1 / avgRerolls) * rerollCost
- console.log(`Cost spent per scarab ${Math.floor(avgRerollCost)}c`)
- const balancePer =
- Math.floor(expectedAvgValue - avgRerollCost) - initialScarabValue
- if (balancePer > 0) console.log(`Avg profit per reroll: ${balancePer}c`)
- else console.log(`Avg loss per reroll: ${balancePer}c`)
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement