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

*To*: mathgroup at smc.vnet.net*Subject*: [mg76599] Re: Mathematica 6.0 easier for me ... (small review)*From*: Ray Koopman <koopman at sfu.ca>*Date*: Thu, 24 May 2007 06:16:11 -0400 (EDT)*References*: <f30vpv$mkn$1@smc.vnet.net>

On May 23, 1:59 am, P... at desinc.com wrote: > ... > 4. At work, I haven't had to resort to other programs because > Mathematica wasn't the best choice. This is extremely nice. BTW, > There's a "temporal" advantage with procedural programming that hasn't > been apparant to me in functional or rule. Still working on it. Maybe > someone can help. 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! > ... lis = {{1,10}, {2,10}, {3,10}, {4,10}, {5,10}, {6,20}, {7,20}, {8,20}, {9,20}, {10,30}, {11,30}, {12,30}, {13,30}, {14,30}, {15,30}, {16,30}, {17,40}, {18,40}, {19,40}, {20,50}, {21,50}}; Extract[ lis, Position[ Rest@# - Most@# & @ lis[[All,2]], 10 ] ] {{5,10},{9,20},{16,30},{19,40}} Two comments: 1. "save the pair" is ambiguous. Which pair? I have returned the list of {i,10j} pairs that precede an {i+1,10{j+1)} pair. 2. This can be done faster but less transparently using SparseArray.