Skip to content

Instantly share code, notes, and snippets.

@hex13
Last active July 4, 2025 20:22
Show Gist options
  • Save hex13/4874cf3df78f8ab50245d64e196f7126 to your computer and use it in GitHub Desktop.
Save hex13/4874cf3df78f8ab50245d64e196f7126 to your computer and use it in GitHub Desktop.
drawing cards
const cards = [['black', 'black'], ['red', 'red'], ['red', 'black']]
const draw = () => cards[~~(Math.random() * 3)];
var rel = 0; // relevant case count
var c = 0; // count of cards when we have red on the other side
for (let i = 0; i < 100000; i++) {
const [b,f] = draw();
if (f == 'black'|| b=='black') {
rel++;
if (b == 'red' || f=='red') c++
}
};
console.log(`rel: ${rel}, count: ${c}, p: ${c/rel}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment