I know it looks like homework ..as I came across some similar java assignments while searching online. It isn't, it's something i just felt like doing. I read a stat that said there was some kind of record for an individual sitting there and fliiping a coin over and over, apparently the longest recorded run was 16 heads. I was curious how long (and how many tries) it took this individual.
Thanks, | [reply] |
/((.)\2*)/; # slightly more general than your requirements, but shoul
+dn't do harm.
Or some variation of it that best fits your needs.
HTH | [reply] [d/l] |
Well ... I could be wrong (I'm no perl guru) but .. why not first cut up the string into H's and T's, place them into an array. Now create a flag $H=0 as an example and then create a simple for loop, where you go though the array and create the appropriate if else statements to get the info you need.
Make sense?
| [reply] [d/l] |
Hrm, I'll try to wrap my head around that, cutting them up and where to is kind of the issue.
I was hoping to do something like:
my $last;
my $count;
my $toss = headsortails(); # returns either 0 or 1 (H or T)
if ($toss == $last) {
$count++;
} else {
$last = $toss;
$c{$count}++;
}
if you had a bunch of variables like $c1, $c2
Thought the implementation didn't really work out. | [reply] [d/l] |