Skip to content

Instantly share code, notes, and snippets.

@danieluhl
Last active January 13, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieluhl/4ad937be0e90efda8748 to your computer and use it in GitHub Desktop.
Save danieluhl/4ad937be0e90efda8748 to your computer and use it in GitHub Desktop.
So you think you're gonna win the lottery? Run this node script to see how lucky you are!
// based on standard powerball lotto of 69 balls for the first 5 and 26 for the "power ball"
// note that this could potentially run forever, running in node should take ~30min but be warned, the browser is much slower!
var _ = require('underscore');
var balls = [];
var powerball = [];
for(var i = 1; i < 70; i++) {
balls.push(i);
}
for(i = 1; i < 27; i++) {
powerball.push(i);
}
var legitLottery = function() {
var count = 0;
var magnitude = 10;
while(true) {
if (count % magnitude === 0) {
if (count > magnitude * 10) {
magnitude = magnitude * 10;
}
console.log('spent: ' + (count * 2).toLocaleString('en-US', {
style: 'currency',
currency: 'USD'
}));
}
balls = _.shuffle(balls);
// using the last powerball numbers - 16, 19, 32, 34, 57, 13
if(balls[0] === 16 &&
balls[1] === 19 &&
balls[2] === 32 &&
balls[3] === 34 &&
balls[4] === 57) {
powerball = _.shuffle(powerball);
if(powerball[0] === 13) {
break;
}
}
count++;
}
console.log('You spent ' + (count * 2).toLocaleString('en-US', {
style: 'currency',
currency: 'USD'
}));
console.log('Your luck is 1 in ' + count);
console.log('Given the 1.5B payout you made ' + (1500000000 - (count * 2)).toLocaleString('en-US', {
style: 'currency',
currency: 'USD'
}));
}
console.time('lottery time');
legitLottery();
console.timeEnd('lottery time');
@danieluhl
Copy link
Author

My first run took ~30min and cost $1.3B for a profit of ~63k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment