Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Runs and Sequences

by uksza (Canon)
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++; } }

Replies are listed 'Best First'.
Re^2: Runs and Sequences
by twofish (Initiate) on Sep 09, 2005 at 12:22 UTC
    uksza, 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?


      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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-10-19 22:14 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (207 votes). Check out past polls.