Created
December 27, 2025 15:48
-
-
Save Ziggoto/c8050f81cd7b372e54f50e69437d7e86 to your computer and use it in GitHub Desktop.
Possible values for two D6s
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
| const allCombinations: Record<string, number> = {}; | |
| let numberCombinations = 0; | |
| for (let a = 1; a <= 6; a++) { | |
| for (let b = 1; b <= 6; b++) { | |
| let sum = a + b; | |
| if (allCombinations?.[sum]) { | |
| allCombinations[sum] = allCombinations[sum] + 1; | |
| } else { | |
| allCombinations[sum] = 1; | |
| } | |
| numberCombinations++; | |
| } | |
| } | |
| console.dir(allCombinations); | |
| console.log(numberCombinations); | |
| const porcentages = Object.fromEntries( | |
| Object.entries(allCombinations).map(([key, value]) => [ | |
| key, | |
| ((value / numberCombinations) * 100).toFixed(2) + '%', | |
| ]), | |
| ); | |
| console.dir(porcentages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment