Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Powerball Frequency Analyzer

by chromatic (Archbishop)
on May 04, 2000 at 18:56 UTC ( [id://10229]=sourcecode: print w/replies, xml ) Need Help??
Category: Webpage Fetcher/Manipulator
Author/Contact Info chromatic
Description: This little darling grabs the lottery numbers from Powerball's web site and runs a quick analysis of the frequency of the picks. It also makes recommendations for the next drawing.

I run it from a cron script every Thursday and Sunday morning.

#!/usr/bin/perl -w

use strict;
use LWP::Simple;

my (@numbers, %normals, %powers);

my $content;

unless (defined ($content = get('http://www.powerball.com/results/pbhi
+st.txt'))) {
    die "Cannot get PB history.\n";
}

@numbers = split /\n/, $content;

my @data;

foreach my $line (@numbers) {
    next if ($line =~ /^!/);
    @data = split(/\s/, $line);
    shift @data;        # throw away the date
    $powers{pop @data}++;

    foreach (@data) {
        $normals{$_}++;
    }
}

print "Normal Pick Rate:\n\n";

my @norm_sort = sort { $normals{$a} <=> $normals{$b} } keys %normals;

foreach (@norm_sort) {
    print "$_ :\t($normals{$_})\t", "*" x $normals{$_}, "\n";
}

print "\nPower Pick Rate:\n\n";

my @power_sort = sort { $powers{$a} <=> $powers{$b} } keys %powers;

foreach (@power_sort) {
    print "$_ :\t($powers{$_})\t", "*" x $powers{$_}, "\n";
}
print "\nNormal Picks:\t";

print join(" ", sort (@norm_sort[0 .. 11])), "\n";

print "\nPower Picks:\t";

print join(" ", sort (@power_sort[0 .. 3])), "\n";

print "\nDisclaimer:\n\tThis is not statistically accurate, except in 
+that the drawings are
guaranteed.\nThis is just a quick frequency analysis making no pretens
+es as to predictive
accuracy.\n";
Replies are listed 'Best First'.
RE: Powerball Frequency Analyzer
by kryten (Scribe) on May 04, 2000 at 21:21 UTC
    So how many times have you won then? :)

    $probability % 2 == 1
    
    (Probability is an odd thing.)
      I was wondering how many times quick pick won in 2002
Re: Powerball Frequency Analyzer
by Anonymous Monk on Apr 04, 2002 at 18:16 UTC
    this seems to be a simple implementation of an even bigger problem. if you were to keep a running tally of the times a number came out over the course of a year, you might be able to analyze it a little bit better than just the days analysis. though, since i'm not a perl guru, you might possibly be doing this, though i see no reference to a database query, or anything that looks like you are opening a file (aside from getting the days numbers)
Re: Powerball Frequency Analyzer
by bnsmith001 (Initiate) on Sep 26, 2008 at 18:30 UTC
    I took a look at chromatic's program from 2000. Great code to start from.

    I updated the code to process the current www.powerball.com winnums-text.txt file, after you've saved it to disk and stripped the one header line, and deleted draws before 08/31/2005 (the last modification to the game).
    Also, my mod'd version of your program -
    1) analyzes powerball and white balls separately,
    2) determines a list of "cold" low count balls, "mid" middle count balls, and "hot" high count balls, and
    3) does not report the Power Pick (or multiplier).

    I will continue to tweek it until it is acceptable to me, and I'll probably post it to a new page here on Perl Monks with the same attribution currently in the code when my verison is to the point that it can --
    1) use GET to access the current file, and
    2) ignore the first header line while processing(will have to change the foreach to a while, I think... I know I've done this before on another Perl project).

    Anyway, here's my copy after working for a few mins updating a couple of things and changing the reported numbers slightly ...

    My current listing follows (I hope) --

    #!/usr/bin/perl -w # originally from http://www.perlmonks.org/ # Powerball Frequency Analyzer # by chromatic (Bishop) # originally based upon old pbhist.txt # updated to current history # also run current "winnums-text.txt" format with no header line # with draws since last rule change in 2005/08/31 # use strict; use warnings; use LWP::Simple; my (@numbers, %normals, %powerb, %powers); my $content; #### bns - updated the link to the draw file ## unless (defined ($content = get('http://www.powerball.com/results/p +bhist.txt'))) { ## die "Cannot get PB history.\n"; ## } ## unless (defined ($content = get('http://www.powerball.com/powerball +/winnums-text.txt'))) { ## die "Cannot get PB history.\n"; ## } unless (defined ($content = get('file:///J:/DivX/current-game-winnums- +text.txt'))) { die "Cannot get PB history.\n"; } @numbers = split /\n/, $content; my @data; foreach my $line (@numbers) { next if ($line =~ /^!/); @data = split(/\s/, $line); shift @data; # throw away the date $powers{pop @data}++; pop @data; $powerb{pop @data}++; foreach (@data) { $normals{$_}++; } } print "Normal (White Ball) Pick Rate:\n\n"; my @norm_sort = sort { $normals{$a} <=> $normals{$b} } keys %normals; foreach (@norm_sort) { print "$_ :\t($normals{$_})\t", "*" x $normals{$_}, "\n"; } print "PowerBall Normal Pick Rate:\n\n"; my @pb_sort = sort { $powerb{$a} <=> $powerb{$b} } keys %powerb; foreach (@pb_sort) { print "$_ :\t($powerb{$_})\t", "*" x $powerb{$_}, "\n"; } print "\nPower Pick Rate:\n\n"; my @pp_sort = sort { $powers{$a} <=> $powers{$b} } keys %powers; foreach (@pp_sort) { print "$_ :\t($powers{$_})\t", "*" x $powers{$_}, "\n"; } print "\nWhite Balls --"; print "\n Cold Picks:\t"; print join(" ", @norm_sort[0 .. 4]), "\n"; print " Mid Picks:\t"; print join(" ", @norm_sort[25 .. 29]), "\n"; print " Hot Picks:\t"; print join(" ", @norm_sort[50 .. 54]), "\n"; print "\nPowerBalls --"; print "\n Cold Picks:\t"; print join(" ", sort (@pb_sort[0 .. 2])), "\n"; print " Mid Pick:\t"; print join(" ", sort (@pb_sort[19 .. 21])), "\n"; print " Hot Picks:\t"; print join(" ", sort (@pb_sort[39 .. 41])), "\n"; ## print "\nPower Picks:\t"; ## print join(" ", sort (@pp_sort[0 .. 3])), "\n"; print "\nDisclaimer:\n\tThis is not statistically accurate, except in +that the drawings are guaranteed.\nThis is just a quick frequency analysis making no pretens +es as to predictive accuracy.\n";
Re: Powerball Frequency Analyzer
by perlNinny (Beadle) on Feb 16, 2011 at 21:05 UTC
    I thought I'd have some fun with this, so I tried it. I had to use the:
    http://www.powerball.com/powerball/winnums-text.txt
    source. I had to do a little alteration in the loop to read the data from site (needed \s+ for the split) and remove the possibility of power balls greater than 39 (can't pick them now). This solution is elegant I think but you all can comment:
    foreach $line(@numbers) { next if ($line =~ /^!/); @data = split(/\s+/, $line); shift @data; # discard date @data = reverse(@data); shift @data if ( @data > 6); # discard power play number if there. $pb = shift @data; $powerb{$pb}++ if($pb<40); foreach (@data) { $normals{$_}++; } }

      Meh. This is elegant:

      my $content = get(...); my @accum = ( undef, (\%normals) x 5, \%powers ); for ( split /\n/, $content ) { my @data = split; $accum[$_]{$data[$_]}++ for 1 .. 6; }
      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
        PerlMonks - have you ever predicted accurately?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://10229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-19 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found