Last active
September 23, 2022 19:19
-
-
Save merryt/1ac4100b2e0ecf037e79e8cb9b31614a to your computer and use it in GitHub Desktop.
In the game wingspan will the next roll contain a nector or not?
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
| diceOptions = ["nectar/wheat", "bug", "nectar/bug", "nectar/cherry", "rat", "fish"] | |
| numberOfRolls = 50000 | |
| target = "nectar" | |
| const rollSinge = () => { | |
| const diceSide = Math.floor(Math.random() * 6) | |
| return diceOptions[diceSide] | |
| } | |
| // generate blank array with n elements | |
| let sim = new Array(numberOfRolls) | |
| .fill([]) | |
| .map( x => [rollSinge(), rollSinge(), rollSinge(), rollSinge(), rollSinge()]) | |
| .filter((birdFeeder)=>{ | |
| simplifiedBirdFeeder = birdFeeder.map(dice => (dice.includes(target) ? target : dice)) | |
| return simplifiedBirdFeeder.includes(target) | |
| }); | |
| console.log(`At least one nector came up ${sim.length/numberOfRolls*100}% of the ${numberOfRolls} rolls`) | |
| const formula = 1-((3/6) ** 5) | |
| console.log(`I think the right math formula is 1-(3/6)^5 or ${formula}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment