Skip to content

Instantly share code, notes, and snippets.

@timhuff timhuff/keno.js

Created Dec 8, 2019
Embed
What would you like to do?
Keno Monte Carlo
/*
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
You can’t perform that action at this time.