Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

RE: Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24244] RE: [mg24241] Pattern Matching
  • From: Wolf Hartmut <hwolf at debis.com>
  • Date: Tue, 4 Jul 2000 15:22:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com



> -----Original Message-----
> From:	Thomas Skipper [SMTP:skipper at worldnet.att.net]
To: mathgroup at smc.vnet.net
> Sent:	Tuesday, July 04, 2000 2:39 AM
> To:	mathgroup at smc.vnet.net
> Subject:	[mg24241] Pattern Matching
> 
> O.K., I know this will seem useless and trivial to quite a few, but
> I'm just playing around here.
> Basically, what I'm doing is this:
> SeedRandom["a list"]
> Then:
> Table[Random[Integer, {1,47}], {any  number}, {6}]
> This produces a list of six numbers picked at random based on the list
> in seed random. ( I think you can see where I'm going with this. My
> friend Peter, a proffessor at Case Western whose specialty is
> Pobabilty and Statistics says I'm all wet, but his dog Bucky, who also
> is usaully pretty wet, thinks I'm on to something, but He's not
> talking)
> Anyway, what I want to find is n number of cases in {list a} that
> match n numbers in {list b}. List a are the groups of six numbers
> produced by Random.
> List b are actual winning numbers. 
> I tried:
> Cases[{%}, {"winning numbers"}], but this will only give me cases that
> match all six (I think). What I want to do is match cases in list
> a(numbers produced by Random) that have 3 of six in list b(acual
> winning nubers), 4 of 6 and so on. I really want to see how many sets
> of six I have to produce to get any practical results, if any.
> 
[Wolf Hartmut]  

Thomas, 

let's assume the winning numbers were {3, 5, 11, 13, 33, 34} then the number
33 is contained ...
 
In[8]:= Count[{3, 5, 11, 13, 33, 34}, 33]
Out[8]= 1

... once. If you have a list of 6 numbers {30, 31, 32, 33, 34, 35} played,
then you can calculate this for each number by mapping

In[9]:= Count[{3, 5, 11, 13, 33, 34}, #] & /@ {30, 31, 32, 33, 34, 35}
Out[9]= {0, 0, 0, 1, 1, 0}

having put the winning numbers into variable 

In[10]:= winning = {3, 5, 11, 13, 33, 34};

the number of hits is just the sum

In[11]:= Plus @@ (Count[winning, #] & /@ {30, 31, 32, 33, 34, 35})
Out[11]= 2

Since you (and Bucky) want to try multiple times, make a function out of
this

In[12]:= Plus @@ (Count[winning, #] & /@ #) &[{30, 31, 32, 33, 34, 35}]
Out[12]= 2


Now I guess your generator is wrong (here over we here draw 6 out of 49, but
any number drawn can only occur once), so we must drop any number x already
drawn (accumulated in r):

In[13]:= draw := Nest[
    Function[r, While[MemberQ[r, x = Random[Integer, {1, 49}]]]; 
      Append[r, x]], {}, 6]


Now I played a thousend times
 
In[14]:= game = Table[draw, {1000}];

...and this were my hits

In[15]:= 
Count[Plus @@ (Count[winning, #] & /@ #) & /@ game, #] & /@ Range[0, 6]
Out[15]= {433, 409, 140, 17, 1, 0, 0}

i.e. I had 17 times 3 of 6 and once 4 of 6 (out of a thousand tries). Before
you try by  yourself, don't forget to replace 49 -> 47 and to (1) calculate
what the bet would have cost you, and (2) the sum you would have won.
Perhaps this will dry, and show _how_ to make a fortune.

Kind regards, hw


  • Prev by Date: Re: Pattern Matching
  • Next by Date: Re: Book quality layout in vers 4 (towards Quark)
  • Previous by thread: Re: Pattern Matching
  • Next by thread: AW: implicit function