MathGroup Archive 2007

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

Search the Archive

Re: How to Map[ f[x,y], {y}]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79227] Re: How to Map[ f[x,y], {y}]?
  • From: Januk <ggroup at sarj.ca>
  • Date: Sat, 21 Jul 2007 04:33:28 -0400 (EDT)
  • References: <f7hqcv$ph7$1@smc.vnet.net>

Hi,

I'm not sure I understand your question.  Are both players drawn from
the same strategy list? There are many possibilities of how to do what
you want:

p1strategy = {17, 3, 17, 3, 17, 3, 17, 3, 17, 3};
p2strategy = RandomInteger[{1,100}, 11];

Probably the simplest is to use a Table command.

(* Mathematica Version 6.0 *)
Table[ score[p1, p2], {p1, p1strategy}, {p2, p2strategy} ]
(* All Mathematica Versions *)
Table[ score[ p1strategy[[i]], p2strategy[[j]] ], {i,
Length[p1strategy]}, {j, Length[p2strategy]} ]

Alternatively, you could make a list with all the combinations of
strategies and then apply your function.  There are multiple ways to
apply your function to this list:

(* Use Apply in shorthand *)
score @@@ Tuples[{p1strategy, p2strategy}]
(* Use ReplaceAll in shorthand *)
Tuples[{p1strategy, p2strategy}] /. {{x__?NumericQ} :> score[x]}

If you prefer the table format, but want something a bit more
functional, you could try:
Function[p1, score[p1, #] & /@ p2strategy] /@ p1strategy

Hope that helps.


On Jul 17, 3:16 am, AngleWyrm <anglew... at yahoo.com> wrote:
> Hi,
> I've got two lists of integers representing player strategies in a game.
>
> I've defined a score function which counts the number of pair-ups where
> the player came out ahead, like so:
>
> strategy = {17, 3, 17, 3, 17, 3, 17, 3, 17, 3}; (* player's plan *)
> score[enemy_]:= Count[strategy - enemy, x_/;x>0];
>
> and I get a total score by comparing a player's strategy against a list of
> possible enemy strategies:
> totalScore = Map[score, strategies] //Sort //Tally
> ListLinePlot[totalScore,{Filling->Axis}]
>
> What I want to do next is create a new version of the scoring function,
> with an interface like: score[p1_, p2_]. Then I want to Map each player's
> strategy against the enemies, and see how they do.
>
> Where I run into problem is how do I Map score[p1,p2] so that p2 is drawn
>  from a list of strategies? Something like Map[ score[p1,p2], strategyList].
>
> Second question is: Is it possible to somehow thread both across the
> strategyList?
>
> --
>
> AngleWyrm




  • Prev by Date: Re: Slow Manipulate with image argument
  • Next by Date: RE: Re: Embedded Style Sheets
  • Previous by thread: How to Map[ f[x,y], {y}]?
  • Next by thread: Re: Copying cells in simple text form?