Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Powerball mania!

by patgas (Friar)
on Aug 23, 2001 at 20:16 UTC ( #107385=perlcraft: print w/replies, xml ) Need Help??

   1: #!/usr/bin/perl -w
   2: use strict;
   3: 
   4: # Lately everyone's been caught up in Powerball fever
   5: # (the jackpot is ~$280 million at time of writing),
   6: # so people around my office were starting to play, and
   7: # I wrote this to analyze the winning numbers history
   8: # text file that powerball.com offers.
   9: 
  10: # (I promise that if I win, I'll donate heavily! :)
  11: 
  12: my ( %numbers, %powerballs, %powerplays );
  13: 
  14: while ( <> ) {
  15:     next if /^!.*$/;
  16:     next if /^\s+$/;
  17:     chomp( my @data = split / / );
  18:     my $date = shift @data;
  19:     $powerplays{pop @data}++ if ( $#data == 6 );
  20:     $powerballs{pop @data}++;
  21:     $numbers{$_}++ foreach @data;
  22: }
  23: 
  24: open OUT, ">powerball.txt" or die "Can't open output file: $!";
  25: 
  26: print OUT <<REGULAR;
  27: Regular Numbers:
  28: Num\tCount
  29: ---\t-----
  30: REGULAR
  31: 
  32: foreach ( sort { $numbers{$b} <=> $numbers{$a} } keys %numbers ) {
  33:     print OUT $_, "\t", $numbers{$_}, "\n";
  34: }
  35: 
  36: for ( 1..49 ) {
  37:     print unless ( $numbers{ sprintf( "%02u", $_ ) } );
  38: }
  39: 
  40: print OUT <<POWERBALL;
  41: 
  42: Powerball Numbers:
  43: Num\tCount
  44: ---\t-----
  45: POWERBALL
  46: 
  47: foreach ( sort { $powerballs{$b} <=> $powerballs{$a} } keys %powerballs ) {
  48:     print OUT $_, "\t", $powerballs{$_}, "\n";
  49: }
  50: 
  51: for ( 1..42 ) {
  52:     print unless ( $powerballs{ sprintf( "%02u", $_ ) } );
  53: }
  54: 
  55: print OUT <<POWERPLAY;
  56: 
  57: Powerplay Numbers:
  58: Num\tCount
  59: ---\t-----
  60: POWERPLAY
  61: 
  62: foreach ( sort { $powerplays{$b} <=> $powerplays{$a} } keys %powerplays ) {
  63:     print OUT $_, "\t", $powerplays{$_}, "\n";
  64: }
  65: 
  66: close OUT;

Replies are listed 'Best First'.
Re: Powerball mania!
by koolade (Pilgrim) on Aug 23, 2001 at 21:52 UTC
Re: Powerball mania!
by ckohl1 (Hermit) on Aug 24, 2001 at 23:51 UTC
    At this point, I think that many programmers are working on the same project...
    #!f:/perl/bin/perl.exe -w use strict; my $PowerballHistoricFile='d:/code/perl/lottery/powerball_numbers.txt' +; my(%History,$Date,@Numbers); open(HISTORY,$PowerballHistoricFile) or die "Could not open $Powerball +HistoricFile!"; foreach my $Line(<HISTORY>){ ($Date,@Numbers)=split(/ /,$Line); $History{$Date}=[@Numbers]; } close(HISTORY); my(%Frequency,%Frequency2); foreach my $Key(sort(keys(%History))){ for my $SubCounter(0..4){ $Frequency{$History{$Key}[$SubCounter]}++; } } foreach my $Key(sort(keys(%Frequency))){ if($Frequency2{$Frequency{$Key}}){ $Frequency2{$Frequency{$Key}}.=", $Key"; } else { $Frequency2{$Frequency{$Key}}=$Key; } } print "Content-Type: text/html\n\n<html><body>\n"; print qq(<br><table border="1" cellpadding="2" cellspacing="0" align=" +center"><caption style="font-size: 15px; font-weight: bold;">Power Ba +ll Historic Information</caption>\n); print qq(<tr bgcolor="#dddddd"><th>Number of Drawings</th><th>Numbers< +/th></tr>\n); foreach my $Key(sort(keys(%Frequency2))){ print qq(<tr><td align="center">$Key</td><td>$Frequency2{$Key}</td +></tr>\n); } print qq(</table>\n</body></html>\n); exit;


    Chris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-09-25 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?