MathGroup Archive 2002

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

Search the Archive

Re: Position within a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32934] Re: [mg32920] Position within a list
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Wed, 20 Feb 2002 01:26:14 -0500 (EST)
  • References: <200202190730.CAA18827@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I don't know about "elegant", but a short solution could be as follows
(notice I'm taking the first 100,000 digits of Pi, instead of 10,000):

In[1]:=
lst = RealDigits[Pi, 10, 100000][[1]];

In[2]:=
Timing[Position[Length /@ Split[lst],
   Max[Length /@ Split[lst]]]]
Out[2]=
{0.82 Second, {{695}}}

This is quite fast, but speed can be much improved by first assigning a name
to the list of lengths, thus avoiding a duplication of the operation:

In[3]:=
a = Length /@ Split[lst]; Timing[Position[a, Max[a]]]
Out[3]=
{0.05 Second, {{695}}}

Tomas Garza
Mexico City

----- Original Message -----
From: "Dana DeLouis" <ng_only at hotmail.com>
To: mathgroup at smc.vnet.net
Subject: [mg32934] [mg32920] Position within a list


> Hello.  A long time ago someone posted an elegant solution, but I can not
> find it in the Archives.
> Given a list that may have repeating data, this returned the character
that
> was repeated the most, and its position..
>
> The example given was a list of the first 10,000 digits of Pi.  I believe
> the answer was that the number 9 was repeated 6 times around position
> 700 or 800.
> The function was very short and elegant.
> I don't believe the Split function was used, but I might be wrong.
>
> Does anyone know how to do this?  Thank you.
>
> lst = RealDigits[Pi,10,10000][[1]];
>
> The list would have...
> {3, 1, 4, 1, 5, 9, 2, 6, etc)
>
>
> --
> Dana DeLouis
> Windows XP  & Mathematica 4.1
> = = = = = = = = = = = = = = = = =
>
>
>
>



  • Prev by Date: Re: Solve/Reduce and assumptions
  • Next by Date: RE: Position within a list
  • Previous by thread: Position within a list
  • Next by thread: Re: Position within a list