Advertisement
SimpleCookie

scarab reroll calc

Sep 19th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function randomInArray(arr) {
  2.   return arr[Math.floor(Math.random() * arr.length)]
  3. }
  4.  
  5. function oddsOfTopThree(rerolls) {
  6.   let count = 0
  7.   const scarabs = [...Array(16).keys()].map((i) => i + 1) // 1-16
  8.   for (let i = 0; i < rerolls; i++) {
  9.     const scarab = randomInArray(scarabs)
  10.     if (scarab > scarabs.length - 3) count++
  11.   }
  12.   return count / rerolls
  13. }
  14.  
  15. function main() {
  16.   const initialScarabValue = 6
  17.   const expectedAvgValue = 42
  18.   const rerollCost = 1
  19.   const rerolls = 1000
  20.   const avgRerolls = oddsOfTopThree(rerolls)
  21.   console.log(`Statisstics is based on ${rerolls} rerolls`)
  22.  
  23.   console.log(`Average rerolls per scarab ${Math.floor(1 / avgRerolls)}c`)
  24.  
  25.   const avgRerollCost = (1 / avgRerolls) * rerollCost
  26.   console.log(`Cost spent per scarab ${Math.floor(avgRerollCost)}c`)
  27.  
  28.   const balancePer =
  29.     Math.floor(expectedAvgValue - avgRerollCost) - initialScarabValue
  30.  
  31.   if (balancePer > 0) console.log(`Avg profit per reroll: ${balancePer}c`)
  32.   else console.log(`Avg loss per reroll: ${balancePer}c`)
  33. }
  34.  
  35. main()
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement