
my $T1 = "HTH";
my $T2 = "HHT";

for (1..1000) {
  @hist = ();
  while (1) {
    push @hist, rand() < .5 ? "H" : "T";
    shift @hist if @hist > 3;
    $s = join "", @hist;
    if ($s eq $T1) { $C1++; last }
    elsif ($s eq $T2) { $C2++; last }
  }
}

print "$C1 $C2\n";

