Skip to content

Instantly share code, notes, and snippets.

@Ziggoto
Created December 27, 2025 15:48
Show Gist options
  • Select an option

  • Save Ziggoto/c8050f81cd7b372e54f50e69437d7e86 to your computer and use it in GitHub Desktop.

Select an option

Save Ziggoto/c8050f81cd7b372e54f50e69437d7e86 to your computer and use it in GitHub Desktop.
Possible values for two D6s
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