0: #!/usr/bin/perl -w
1: use strict;
2:
3: # Lately everyone's been caught up in Powerball fever
4: # (the jackpot is ~$280 million at time of writing),
5: # so people around my office were starting to play, and
6: # I wrote this to analyze the winning numbers history
7: # text file that powerball.com offers.
8:
9: # (I promise that if I win, I'll donate heavily! :)
10:
11: my ( %numbers, %powerballs, %powerplays );
12:
13: while ( <> ) {
14: next if /^!.*$/;
15: next if /^\s+$/;
16: chomp( my @data = split / / );
17: my $date = shift @data;
18: $powerplays{pop @data}++ if ( $#data == 6 );
19: $powerballs{pop @data}++;
20: $numbers{$_}++ foreach @data;
21: }
22:
23: open OUT, ">powerball.txt" or die "Can't open output file: $!";
24:
25: print OUT <<REGULAR;
26: Regular Numbers:
27: Num\tCount
28: ---\t-----
29: REGULAR
30:
31: foreach ( sort { $numbers{$b} <=> $numbers{$a} } keys %numbers ) {
32: print OUT $_, "\t", $numbers{$_}, "\n";
33: }
34:
35: for ( 1..49 ) {
36: print unless ( $numbers{ sprintf( "%02u", $_ ) } );
37: }
38:
39: print OUT <<POWERBALL;
40:
41: Powerball Numbers:
42: Num\tCount
43: ---\t-----
44: POWERBALL
45:
46: foreach ( sort { $powerballs{$b} <=> $powerballs{$a} } keys %powerballs ) {
47: print OUT $_, "\t", $powerballs{$_}, "\n";
48: }
49:
50: for ( 1..42 ) {
51: print unless ( $powerballs{ sprintf( "%02u", $_ ) } );
52: }
53:
54: print OUT <<POWERPLAY;
55:
56: Powerplay Numbers:
57: Num\tCount
58: ---\t-----
59: POWERPLAY
60:
61: foreach ( sort { $powerplays{$b} <=> $powerplays{$a} } keys %powerplays ) {
62: print OUT $_, "\t", $powerplays{$_}, "\n";
63: }
64:
65: close OUT;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|