fd
Posts:
43
Registered:
7/24/09


Re: tossing a coin
Posted:
May 30, 2013 6:08 AM


Hi,
A variation of Dana's answer, if you'd like to keep the tossing results as a list
In[2]:= k = RandomChoice[{"h", "t"}, 30]
Out[2]= {"t", "h", "h", "h", "t", "t", "h", "t", "h", "h", "h", "t", \ "t", "t", "t", "h", "t", "h", "h", "t", "t", "t", "h", "h", "t", "h", \ "t", "t", "t", "h"}
In[8]:= k //. {x___, "t", "h", "h", y___} :> {x, "PATTERN A", y}
Out[8]= {"PATTERN A", "h", "t", "t", "h", "PATTERN A", "h", "t", "t", \ "t", "t", "h", "PATTERN A", "t", "t", "PATTERN A", "t", "h", "t", \ "t", "t", "h"}
A more literal way is to create the sequences by partitioning with padding
In[29]:= Position[Partition[k, 3, 1], {"t", "h", "h"}]
Out[29]= {{1}, {8}, {17}, {22}}
Best Regards

