Re: Mathematica 6.0 easier for me ... (small review)

• To: mathgroup at smc.vnet.net
• Subject: [mg76556] Re: [mg76457] Mathematica 6.0 easier for me ... (small review)
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Thu, 24 May 2007 05:53:53 -0400 (EDT)
• References: <200705230859.EAA23180@smc.vnet.net>

```On 23 May 2007, at 17:59, Paul at desinc.com wrote:

> If I have
> lis={{1,10},{2,10},...{9,10},{11,20},{12,20}...{19,20}
>
> How do I use functional and/or rule to determine where the second
> number (lis[[i,2]]) jumped from 10 to 20 to 30 and save the pair.
> Assuming there was noise, I only want to store the first 10->20, then
> look for 20->30 and so on.  So in time, I want my search to change as
> I progress through the list.  Any input appreciated!

I am not quite sure if I really understand what you wish to do. But
if what I think is correct, then it seems easy to do it using rule
based programming:

FirstJump[lis_, n_, m_] := Flatten[({
lis} /. {___, {x_, n}, {y_, m}, ___} :> Position[lis, {x, n}])]

For example:

ls={{1,10},{2,10},{9,10},{11,20},{12,20},{19,20},{20,30}};

FirstJump[ls,10,20]

{3}

FirstJump[ls,20,30]

{6}

The above assumes that all the pairs in your list are distinct. If
they are not, then something more complicated is needed, e.g.:

Clear[FirstJump]

FirstJump[lis_, n_, m_] := Position[Flatten[({lis} /. {a___, {x_, n}, {
y_, m}, b___} :> {a, \$1, \$2, b}), 1], \$1, 1]

ls = {{1,10}, {2, 10}, {9, 10}, {9, 10}, {11, 20}, {12, 20}, {19,
20}, {20, 30}};

FirstJump[ls, 10, 20]

{{4}}

Andrzej Kozlowski

```

• Prev by Date: Re: Re: what are the options for the "String"
• Next by Date: Best strategy for using Drawing Tools
• Previous by thread: Mathematica 6.0 easier for me ... (small review)
• Next by thread: Re: Mathematica 6.0 easier for me ... (small review)