The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: tossing a coin
Replies: 3   Last Post: May 30, 2013 6:08 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 43
Registered: 7/24/09
Re: tossing a coin
Posted: May 30, 2013 6:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.