Re: problems with delayed write: tag list

• To: mathgroup at smc.vnet.net
• Subject: [mg79902] Re: [mg79877] problems with delayed write: tag list
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Wed, 8 Aug 2007 04:54:41 -0400 (EDT)
• References: <15673831.1186475964153.JavaMail.root@m35>

```I assume you mean nowFunction to be some kind of "inverse" function, which
takes a difference to the index or indices where that difference is
achieved.

In each case below, Scan defines the inverse, and then I list its values
at the observed differences.

n = 20;
myList = Transpose[{Range@Length@#, #}] &@RandomInteger[{1, 10}, n]
differences = myList.{-1, 1}

{{1, 2}, {2, 10}, {3, 7}, {4, 8}, {5, 3}, {6, 4}, {7, 1}, {8, 5}, {9,
9}, {10, 10}, {11, 3}, {12, 2}, {13, 1}, {14, 1}, {15, 1}, {16,
9}, {17, 3}, {18, 8}, {19, 4}, {20, 6}}

{1, 8, 4, 4, -2, -2, -6, -3, 0, 0, -8, -10, -12, -13, -14, -7, -14, \
-10, -15, -14}

Clear[lastFound]
Scan[(lastFound[#.{-1, 1}] = #.{1, 0}) &, myList];
lastFound /@ differences

{1, 2, 4, 4, 6, 6, 7, 8, 10, 10, 11, 18, 13, 14, 20, 16, 20, 18, 19, \
20}

Clear[allFound]
allFound[i_] = {};
Scan[(allFound[#.{-1, 1}] = Append[allFound[#.{-1, 1}], #.{1, 0}]) &,
myList];
allFound /@ differences

{{1}, {2}, {3, 4}, {3, 4}, {5, 6}, {5, 6}, {7}, {8}, {9, 10}, {9,
10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {15, 17,
20}, {12, 18}, {19}, {15, 17, 20}}

Clear[find, firstFound]
find[{j_Integer, x_}] /; Head[firstFound[x - j]] === firstFound :==

firstFound[x - j] = j
Scan[find, myList];
firstFound /@ differences

{1, 2, 3, 3, 5, 5, 7, 8, 9, 9, 11, 12, 13, 14, 15, 16, 15, 12, 19, 15}

This is similar to your original attempt:

i = 0;
now = Reap[
While[i < Length@myList,
i++; Sow[i, myList[[i]].{-1, 1}]
]]

{Null, {{1}, {2}, {3, 4}, {5, 6}, {7}, {8}, {9, 10}, {11}, {12,
18}, {13}, {14}, {15, 17, 20}, {16}, {19}}}

or this:

Clear[allFound]
i = 0;
now = Reap[
While[i < Length@myList,
i++; Sow[i, myList[[i]].{-1, 1}]
], _, (allFound[#1] = #2) &]
allFound /@ differences

{Null, {{1}, {2}, {3, 4}, {5, 6}, {7}, {8}, {9, 10}, {11}, {12,
18}, {13}, {14}, {15, 17, 20}, {16}, {19}}}

{{1}, {2}, {3, 4}, {3, 4}, {5, 6}, {5, 6}, {7}, {8}, {9, 10}, {9,
10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {15, 17,
20}, {12, 18}, {19}, {15, 17, 20}}

Bobby

On Tue, 07 Aug 2007 00:38:06 -0500, P_ter <peter_van_summeren at yahoo.co.u=
k>  =

wrote:

> Hello,
> I have a list of elements of two numbers:myList = {{1,2},{2,7},..}. =
The  =

> first number is in this case always the position. I want to know when =
=

> the difference is a certain value,myDiff, eg. 5
> i=1;myDiff==5;
> now= Reap[While[i<Length[myList],i++;
>        If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w]
> My question is: how do I make "nowFunction[myDiff_]:="?
> I run into tag list errors in the definition when I try that.
> P_ter
>
>

-- =

DrMajorBob at bigfoot.com

```

• Prev by Date: show residuals of circle fit
• Next by Date: Re: Two different packages can not Need[] the same utility package?
• Previous by thread: Re: problems with delayed write: tag list
• Next by thread: Re: problems with delayed write: tag list