Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Extracting information from lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63359] Re: Extracting information from lists
  • From: "dkr" <dkrjeg at adelphia.net>
  • Date: Sun, 25 Dec 2005 02:19:37 -0500 (EST)
  • References: <dojefh$fmb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Tony,

To extract the positions of the first element of runs of a given
integer within a list, a very simple approach is to let a regex do all
the dirty work:

In[23]:=
posFn[x:{__Integer},elem_Integer]:=
    First/@StringPosition[StringJoin[ToString/@x],
        RegularExpression[ToString[elem]<>"+"],Overlaps->False];
In[25]:=
posFn[{11791681165111876111171},1]
Out[25]=
{1,5,8,12,18,23}
In[26]:=
posFn[{79168116511187611117},1]
Out[26]=
{3,6,10,16}
In[27]:=
posFn[{79168116511187611117},8]
Out[27]=
{5,13}

An equivalent formulation using Mathematica string expressions would
be:

posFnAlt[x:{__Integer},elem_Integer]:=
    First/@StringPosition[StringJoin[ToString/@x],ToString[elem]..,
        Overlaps->False];

dkr


  • Prev by Date: Re: Re: Replacement equivalence?
  • Next by Date: Re: Extracting information from lists
  • Previous by thread: Re: Extracting information from lists
  • Next by thread: Re: Extracting information from lists