MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: tossing a coin

  • To: mathgroup at
  • Subject: [mg130968] Re: tossing a coin
  • From: Felipe <fdimer at>
  • Date: Thu, 30 May 2013 06:15:05 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <> <ko1nbl$r31$>


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

  • References:
  • Prev by Date: Re: Warsaw Univ. course, was Re: Work on Basic Mathematica Stephen!
  • Next by Date: Applying Mathematica to practical problems
  • Previous by thread: Re: tossing a coin
  • Next by thread: Re: tossing a coin