Re: Extending Gaylord's Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg5030] Re: Extending Gaylord's Problem
- From: espen.haslund at fys.uio.no (Espen Haslund)
- Date: Sat, 19 Oct 1996 16:40:33 -0400
- Organization: Universitet i Oslo
- Sender: owner-wri-mathgroup at wolfram.com
In article <542t6a$p9f at dragonfly.wolfram.com>, jackgold at math.lsa.umich.edu says... > >Hi Group; .... > Suppose we have m lists labelled L1, L2, ..., Lm. We form a >new list Lnew by taking the maximum of the first entries of the lists >L1,..., Lm. The winning element is removed from the list in which it >appeared and the second element of that list becomes its new first >element. In the event of a tie, choose the element from the list with >the lowest subscript. Repeat until Lnew contains r entries. (r is >set in advance and cannot be more than the total number of entries in >all of the lists.) When all the elements of a list are gone, the >selection proceeds without that list. It seems to me that this game >has a unique solution, but programming it appears somewhat of a >challange. The lengths of the lists need not be equal, but they can >always be arranged so by adding sufficiently many -Infinity at the >end of the shorter lists. > > Incidentally, Gaylord's Problem is a special case with m = 2. >Simply let L2 = Reverse[L1] and r = Length[L1]. > >Jack Goldberg > > Hi Jack; I think maybe this one meets your specifications. It is more or less an extension of Allan Hayes solution to Gaylord's Problem. takeFirst[data_, n_:-1] := Module[{r, k, i, ii, big, lis, ll}, ll = Map[Length, data]; If[n == -1, r = Plus @@ ll, r = n]; ii = Table[1, {Length[data]}]; Table[ big = -Infinity; Do[ lis = data[[j]]; If[(i = ii[[j]]) <= ll[[j]], If[lis[[i]] >= big, big = lis[[i]]; k = j ] ], {j, Length[data], 1, -1}]; ii[[k]] = ii[[k]] + 1; big, {r}] ]; (* data -- {L1, L2, ..., Ln} *) -Espen