Last active
January 13, 2016 21:46
-
-
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!
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
// 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My first run took ~30min and cost $1.3B for a profit of ~63k