Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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 ]
fd

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

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




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.