simple underscore.js projects, walk through, & tutorial


Lottery DataBase Analysis - 06 (_.reduce)


California Lucky for Life (832)
Prizes Odds 1 in Total # of Winners Prizes Claimed Prizes Available
$3,250,000 2,400,000 17 11 6
$5,000 1,200,000 34 22 12
$1,000 400,000 102 65 37
$500 12,000 3,400 2,239 1,161
$100 645 63,240 41,624 21,616
$40 350 116,620 76,812 39,808
$20 53 765,000 498,167 266,833
$15 40 1,020,000 668,467 351,533
$10 20 2,040,000 1,325,571 714,429
$5 11 3,570,000 2,287,131 1,282,869
Ticket 10 4,080,000 2,524,475 1,555,525



    // prizeAmounts, value of winnings
    var prizeAmounts = _.pluck(game832Data, "Prizes");
    prizeAmounts = _.map(prizeAmounts, function(n){return n.replace(/Ticket/g, "$5");});
    prizeAmounts = _.map(prizeAmounts, function(n){return n.replace(/\$/g, "");});
    prizeAmounts = _.map(prizeAmounts, function(n){return parseInt(n.replace(/,/g,""),10);});
    document.getElementById('outputOne').innerHTML = _.map(prizeAmounts, function(n){return ' ' + n;});

var prizeAmounts =
1 Nada Yet



    //Payout Per prizeAmount type
    //var payoutPerPrizeAmount = _.zip(numWin, prizeAmounts);
    var ppPrize = _.zip(numWin, prizeAmounts);
    var payoutPerPrizeAmount = _.map(ppPrize,
        function(passedArray){
            return passedArray[0] * passedArray[1];
        });
    document.getElementById('outputTwo').innerHTML = _.map(payoutPerPrizeAmount, function(n){return ' ' + n;});

Payout Per Prize Amount = :
2 Nada Yet



    //Total Payout
    var totalMoneyOut = _.reduce(payoutPerPrizeAmount, function(start, num){return start + num;});
    document.getElementById('outputThree').innerHTML = "Total Amount of Prizes Paid Out = $" + totalMoneyOut;

3 Nada Yet



    //Total Price of All Tickets
    // 5 = ticket price, magic Number
    var costAllTicketsInGame = totalPlays[0] * 5;
    var tempFourForOutput = "Total Cost of All Tickets in Game = $" + costAllTicketsInGame;
    document.getElementById('outputFour').innerHTML = tempFourForOutput;

4 Nada Yet



    // Payout Percentage
    var payoutRatio = totalMoneyOut/costAllTicketsInGame
    document.getElementById('outputFive').innerHTML =  payoutRatio;

5 Nada Yet


Rumor is (or so I have heard, perhaps incorrectly) that the payout percentage in Vegas is mandated by law at 80% (for slots and the like), so 77% seems spot on to me and quite favorable.  I had thought the lottery set the payout Percentage at 50%, so if I am wrong it that, maybe the value varies from game to game.  And if so, that will be a good stat to track and carry forward.  With that in mind, it's probably time to start working on a consistent output (end of page summary), perhaps with graphs and whatnot.  Perhaps...




_.moreUnderscoreProjects

© Copyright 2013 Brett Paufler



Please Note: I am an idiot.  No seriously.  The odds of my gambling odds calculations being correct are likely on par with my odds of ever winning.  You have been warned.