There's more than one way to do things PerlMonks

### Re: Runs and Sequences

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

[download]

Replies are listed 'Best First'.
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

Create A New User
Node Status?
node history
Node Type: note [id://490533]
help
Chatterbox?
 [thezip]: So I have a script that generates a log file. After script completion, I want tohave VIM open this logfile. [thezip]: i don't get the command line "back" until I close VIM. No what I want to happen... [thezip]: I currently don't have access to CYGWIN, else I'd just do a tail -f on the logfile. [Corion]: thezip: If you want to open vim and can live with opening a second console window, use start "The results" vim.exe c:\path\to\logfile .log [thezip]: Ooops... I lied. I guess Cygwin is back. I'll just do a tail -f instead. Better. Sorry for the noise.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2017-03-27 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (321 votes). Check out past polls.