Created
December 8, 2019 00:25
-
-
Save timhuff/835a667a1de82de3247a3864330c04be to your computer and use it in GitHub Desktop.
Keno Monte Carlo
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
/* | |
Output: | |
Pick 1 winnings per game: -0.499308 | |
Pick 2 winnings per game: -0.39711 | |
Pick 3 winnings per game: -0.377799 | |
Pick 4 winnings per game: -0.387787 | |
Pick 5 winnings per game: -0.381384 | |
Pick 6 winnings per game: -0.430624 | |
Pick 7 winnings per game: -0.440436 | |
Pick 8 winnings per game: -0.407179 | |
Pick 9 winnings per game: -0.441691 | |
Pick 10 winnings per game: -0.404874 | |
/* | |
const _ = require('lodash') | |
const numGames = 1000000 | |
const numbers = _.range(1, 81) | |
let bank = 0 | |
const payoffs = { | |
1: { | |
1: 2 | |
}, | |
2: { | |
2: 10 | |
}, | |
3: { | |
2: 2, | |
3: 25 | |
}, | |
4: { | |
2: 1, | |
3: 5, | |
4: 60 | |
}, | |
5: { | |
3: 2, | |
4: 20, | |
5: 330 | |
}, | |
6: { | |
3: 1, | |
4: 6, | |
5: 55, | |
6: 1000 | |
}, | |
7: { | |
3: 1, | |
4: 2, | |
5: 15, | |
6: 100, | |
7: 5000 | |
}, | |
8: { | |
4: 2, | |
5: 6, | |
6: 75, | |
7: 550, | |
8: 10000 | |
}, | |
9: { | |
4: 1, | |
5: 5, | |
6: 20, | |
7: 125, | |
8: 3000, | |
9: 30000 | |
}, | |
10: { | |
0: 5, | |
5: 2, | |
6: 10, | |
7: 45, | |
8: 300, | |
9: 5000, | |
10: 100000 | |
}, | |
} | |
for (let pickN = 1; pickN <= 10; pickN++) { | |
bank = 0 | |
for (let i = 0; i < numGames; i++) { | |
bank -= 1 | |
const guesses = _.sampleSize(numbers, pickN) | |
const picks = _.sampleSize(numbers, 20) | |
const numMatches = _.intersection(guesses, picks).length | |
const winnings = payoffs[pickN][numMatches] || 0 | |
bank += winnings | |
} | |
console.log(`Pick ${pickN} winnings per game: ${bank / numGames}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment