Created
August 7, 2026 18:26
-
-
Save bxt/2e450a96487203315814626e6517d5ea to your computer and use it in GitHub Desktop.
Game 10k
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
| // 1 dice = 1/6 -> 5 -> 50, 1/6 -> 1 -> 100 -> 4/6 screwed | |
| // 2 dice | |
| const dicePoints = [100, 0, 0, 0, 50, 0]; | |
| function dicePoint(dice: number): number { | |
| return dicePoints[dice - 1]; | |
| } | |
| function game10kPoints(dices: number[]): number { | |
| if (dices.length === 0) return 0; | |
| if (dices.length === 1) return dicePoint(dices[0]); | |
| if (dices.length === 2) { | |
| const [aP, bP] = dices.map(dicePoint); | |
| if (aP === 0 || bP === 0) return 0; | |
| return aP + bP; | |
| } | |
| if (dices.length === 3) { | |
| const [a, b, c] = dices; | |
| if (a === b && b === c) return a * 100; | |
| } | |
| return 0; | |
| } | |
| function randomDice(): number { | |
| return Math.floor(Math.random() * 6) + 1; | |
| } | |
| function randomDices(length: number): number[] { | |
| return Array.from({ length }, randomDice); | |
| } | |
| function play10k() { | |
| let dices = 5; | |
| let points = 0; | |
| while (dices > 0) { | |
| const roll = randomDices(dices); | |
| console.log("I rolled", roll); | |
| if (roll.includes(1)) { | |
| console.log("Take a 1 for 100 points"); | |
| points += 100; | |
| dices--; | |
| } else if (roll.includes(5)) { | |
| console.log("Take a 5 for 50 points"); | |
| points += 50; | |
| dices--; | |
| } else { | |
| console.log("Lost!"); | |
| points = 0; | |
| dices = 0; | |
| } | |
| } | |
| console.log(`Result: ${points}`); | |
| } | |
| play10k(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment