Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

barbie (2653)

  reversethis-{ku. ... m} {ta} {eibrab}

Leader of [] and a CPAN author []. Co-organised YAPC::Europe in 2006 and the 2009 QA Hackathon, responsible for the YAPC Conference Surveys [] and the QA Hackathon [] websites. Also the current caretaker for the CPAN Testers websites and data stores.

If you really want to find out more, buy me a Guinness ;)

Memoirs of a Roadie []
CPAN Testers Reports []
YAPC Conference Surveys []
QA Hackathon []

Journal of barbie (2653)

Wednesday June 25, 2003
06:59 AM

The Lottery

[ #13053 ]
After watching Nicole's brother disappointment when the lottery numbers came up on Saturday, I thought I'd write a prediction script. It does two predictions, the first is based on all the previous draws and the second is based on random numbers. Not too surprisingly it showed that predictions based on previous draws gave a better return than the random predictions, and that both paid out less than the cost of the predictions.

The initial script was based on upto 10 lines each per draw. Eliminating duplicates (numbers in lines and lines themselves) sometimes reduced to less than 10. There have been over 700 draws so far to work with, so not a bad amount of sample data. I'm trying some tweaks, but I still think you only win by not playing.

However, I think I won as I got to play with and understand pack() better and used The Guttman-Rosler Transform to speed up the sorting process. Now I just need to figure a quick way of calculating the number of unique characters in a given string.

Currently reading Dave Cross' Data Munging With Perl, which is proving a nice refresher to stuff I haven't done in a while.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I'm still a bit in golf mode, but here's a possibility:
    $uniq_chars = keys %{{ split /()/, $string }};
    • Odd number of elements in anonymous hash at line 5.

      It doesn't like having an odd number of characters in the string length. Looks like the basis for what I was after, so some tweaking might be in order.

      Thanks for the suggestion.

      • Oops, I forgot to turn on warnings when I ran the one-liner (told you I was in golf mode!). Actually it gives the warning even if the string has an even number of characters. Here's a variation:
        $uniq_chars = keys %{{ $string =~ /(.)()/gs }};
        • I thought I'd do a bit of benchmarking and was rather surprised at the results.

          This was the code:

          #!/usr/bin/perl -w
          use strict;

          use Benchmark qw(:all);

          my $string = "ABCDEEsdasdasdfsadfwewasdaSD";

          cmpthese(100000, {
              'foreach' => \&do_foreach,
              'map' => \&do_map,
              'split' => \&do_split,

          sub do_foreach {
              my %hash;
              foreach ( split //, $string ) { $hash{$_}=1; }
              my $uniq_chars = keys %hash;

          sub do_map {

  • I'm probably being exceptionally silly, but why would predictions based on previous draws give you better results than random numbers?
    • Theoretically they shouldn't, but if there is a set of numbers or even a sequence of numbers that persistantly appear in draws, then using them seems to have a better chance of winning small prizes.

      In all the test runs I've done so far there has only one prediction that has made a bonus+5 win, and that was from the predictions based on previous draws.

      It doesn't prove anything and I only wrote it to wile away the hours on a Sunday. But it did prove useful for learning about the sorting and other alogrith

    • It doesn't. The only thing you can maximize by analyzing previous drawings is your possible win (by choosing numbers which are not frequently played by your fellow players).
      • ...waaaait, wouldn't that only be true if there were no pattern in the numbers?

        You are what you think.
        • Patterns - Yes... but not in the numbers that are drawn but in the numbers which are chosen by other players.
          • even if there's a pattern in the numbers being drawn, it's irrelevant to trying to win more? Why wouldn't finding that pattern produce increased winnings?

            This can't be the Monty Hall problem...what's the deal?


            You are what you think.