Created
March 14, 2023 12:46
-
-
Save shiv122/06e9149c8dea33fbfb407b2755eeae59 to your computer and use it in GitHub Desktop.
calculate dice
This file contains 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
function calculateDiceProbabilities(history) { | |
const counts = [0, 0, 0, 0, 0, 0]; | |
// Count the occurrences of each number in the history | |
for (let i = 0; i < history.length; i++) { | |
const roll = history[i]; | |
if (roll >= 1 && roll <= 6) { | |
counts[roll - 1]++; | |
} | |
} | |
const totalRolls = history.length; | |
const probabilities = counts.map(count => count / totalRolls); | |
return probabilities; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment