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

Re: Runs and Sequences

by uksza (Monsignor)
on Sep 09, 2005 at 12:04 UTC ( #490533=note: print w/ replies, xml ) Need Help??


in reply to Runs and Sequences

Update: longest value.

#!/usr/local/bin/perl use strict; use warnings; my ($h, $t, $last, $lt, $lh) = (0,0,"T",0,0); while () { my $random = int( rand(2)); if ($random == 0) { print "T $t times. Longest $lt\n" if $t; $lt<$t?$lt=$t:(); $t=0; $h++; } if ($random == 1) { print "H $h times. Longest $lh\n" if $h; $lh<$h?$lh=$h:(); $h=0; $t++; } }


Comment on Re: Runs and Sequences
Download Code
Re^2: Runs and Sequences
by twofish (Initiate) on Sep 09, 2005 at 12:22 UTC
    uksza ..wow, for the most part exactly what I was looking for, you're fast. Thanks to Roy Johnson also. I think this gives me a couple different ways I can generate and parse through the data. I'll work on customizing it to find and grab some other stats that might be kind of cool (like how many tries somone would have to go through on average to get a run of 16 ..should be around 1/(2^16).
    Thanks a lot!
      I'm no mathematician, but shouldn't it be 2/(2^16) = 1/2^15? I mean you can have a string of either all heads or all tails, right?

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://490533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-04-21 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls