Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Simple Lottery

by xgunnerx (Initiate)
on May 21, 2002 at 22:00 UTC ( #168293=sourcecode: print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info xgunnerx
Description: Simple lottery program. Will stop running and tell you the outcome when all six numbers are met.
#!/usr/bin/perl -w

use strict;
my (%pick, %rand) = ();
my ($plays, $money, $years, $week, $win, $count) = 0;

print "How many times do you play the lottery every week?\n";
chomp(my $wcheck = <>);
$week = ($wcheck * 52);

print "Please enter 6 numbers for the lottery: \n";
while ($count < 6) {
    print "Enter lottery number $count: ";
    chomp(my $num = <>);
    $count-- and print "That is not a valid input, please enter a numb
+er between 1 and 54\n" and next if $num > 54 || !($num =~ /^\d+$/);
    $pick{"$count"} = "$num";

## Start our search!
while () {
    undef $win;
    my $i = 0;
    while ($i <= 6) { $i++; $rand{$i} = int(rand(54)) + 1;}
    foreach my $x (keys (%rand)) {
        foreach my $y (keys(%pick)) {
            $win++, next if $pick{$y} == $rand{$x};
    $money += 1000000 and last if $win == 6;
    $money += 1000 if $win == 5;
    $money += 100 if $win == 4;
    $money += 5 if $win == 3;
    print "We won \$$money dollars so far, in $plays plays\n";
print "We won \$$money dollars in $plays plays!\n";

## Figure out how long it took us to hit the jackpot and print finding
if ($plays >= $week) {
    $years = sprintf "%.1f", ($plays / $week);
    print "It took us $years years to hit the jackpot at $wcheck plays
+ a week. We won \$$money dollars!\n";
else { print "It took us less than a year to hit the jackpot. We won \
+$$money dollars!\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://168293]
[Discipulus]: rend out the xls IF i have access to the DB
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)
[ambrus]: Corion: those are good rules.
[ambrus]: Discipulus: oh sure. the input data has different filenames every time I get them.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2017-03-29 12:12 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.