I think this is an interesting problem. The New Jersey
lottery this week is at $200 million. Since I am the only
person who lives in Jersey I was in charge of getting the
tickets. Well, maybe I was the only person who would ADMIT
they live in New Jersey. I lived in New York my whole life
so I had to take the cheap shot. I looked up there
webpage at http://www.state.nj.us/lottery/bigrules.htm.
I would like to calculate the probability of winning the
lottery. Here is a segment from the website:
The purchaser shall select or "Quick Pick" any five (5)
numbers, from a range of consecutive numbers of 1 through
50 and one (1) number from a range of consecutive numbers
of 1 through 36. Bet selections of less than or more than
six (6) numbers will be impermissible.
I was never very good at math and I was usually disrupting
the class instead of paying attention anyway. I am probably
ADD, but I digress. Its also scary how much this post looks
like one of those dorky math problems I had to do, but perl
makes it interesting. Here is what I remember about probability
50 * 49 * 48 * 47 * 46 * 36 = $probability;
However, this is very boring and inflexible. I tried to write
it in perl.
use strict;
use integer;
my $probability;
&permutation(50,5);
print $probability * 36;
sub permutation {
my ($number, $times, $counter);
($number, $times) = @_;
print "The times is $times and the number is $number.\n";
my $counter = '1';
while ($counter < $times) {
$probability = $number * ($number - $counter);
$counter++;
$number--;
print $number, "\n";
}
return $probability;
}
Unfortunately, $probability gets written over with
each iteration.
If you want real bonus points calculate how much we could
win AFTER taxes. I have 21 people signed up and we all
put in $5.00. We are using quick pick and cash up
front.
Ergowolf
Applying Perl to the Real World
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.