filter?

Michael Kann mikekann at yahoo.com
Thu Jun 23 09:39:39 EDT 2011


Nicolas and others,

Boy, I'm learning a lot about arrays. Thanks. 

If we're going to sort, we could sort the unique values to the top, then only loop down until we hit a duplicate value. Something like the following:


function f v,x
 if x & cr & x is in v then
   return 1
 else 
   return zero
 end if
end f


on mouseUp

put fld 1 into v -- both lists together
sort v
sort v numeric by f(v,each)

put "STARTER" into previous_x

repeat for each line x in v
    if x is previous_x then
      delete last line of h
      exit repeat
    end if
  put x & cr after h
  put x into previous_x
end repeat

put h into fld 2 -- unique values

end mouseUp



--- On Wed, 6/22/11, Nicolas Cueto <niconiko at gmail.com> wrote:

From: Nicolas Cueto <niconiko at gmail.com>
Subject: Re: filter?
To: "How to use LiveCode" <use-livecode at lists.runrev.com>
Date: Wednesday, June 22, 2011, 11:23 PM

Went with Michael Kann's solution.

Thanks to all, tho.

BTW, my request's reason had to do with Livecode's odd group behaviour.

--
Nicolas Cueto (iPhone)

On 2011/06/23, at 11:19, Michael Kann <mikekann at yahoo.com> wrote:

> If you want to use a SORT you can try something like the following:
> 
> on mouseUp
> put "1,2,3,4" into v
> put "1,2,3,4,5" & cr before v
> replace comma with cr in v
> sort v
> repeat for each line x in v
>   if x & cr & x is not in v then
>     put x & cr after h
>   end if
> end repeat
> put h into fld 3 -- "5"
> end mouseUp
> 
> --- On Wed, 6/22/11, Pete <pete at mollysrevenge.com> wrote:
> 
> From: Pete <pete at mollysrevenge.com>
> Subject: Re: filter?
> To: "How to use LiveCode" <use-livecode at lists.runrev.com>
> Date: Wednesday, June 22, 2011, 8:30 PM
> 
> I have a feeling this is probably going to get a lot of responses related to
> the most efficient way to do this!  I have no idea how efficient this would
> be but I'll start the ball rolling with this code.
> 
> repeat with x=1 to the number of lines in tlist1
>   if line x of tlist1 is not among the lines of tlist 2 then
>     < you found a unique tlist1 value >
>   end if
> end repeat
> repeat with x=1 to the number of lines in tlist2
>   if line x of tlist2 is not among the lines of tlist1 then
>     < you found a unique tlist2 value >
>   end if
> end repeat
> 
> Another thought I had involves using an array as follows:
> 
> repeat with x=1 to the number of lines in tlist1
>   add 1 to array[line x of tlist1]
> end repeat
> repeat with x=1 to the number of lines in tlist2
>   add 1 to array[line x of tlist2]
> end repeat
> repeat for each key myKey in array
>   if array[myKey]=1 then
>     < you found a unique value >
>   end if
> end repeat
> 
> Depending on how many entries you expect in each list and how long each
> entry is, the array solution could chew up a huge amount of memory.
> 
> These are both pretty simplistic solutions which probably means they
> wouldn't be the fastest.  I have no idea how fast either of them might be
> and I know there are definitely some efficiencies to be had by using either
> repeat with vs repeat for but I can't remember which is the faster.
> 
> 
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> 
> 
> 
> 
> On Wed, Jun 22, 2011 at 5:38 PM, Nicolas Cueto <niconiko at gmail.com> wrote:
> 
>> Hi again.
>> 
>> Given 2 lists of cr-delimited values (tList1, tList2), what's the fastest
>> way of getting the unique value(s)?
>> 
>> Ex, "1,2,3,4" & "1,2,3,4,5" = "5"
>> (but cr instead of comma)
>> 
>> Thanks.
>> 
>> --
>> Nicolas Cueto (iPhone)
>> _______________________________________________
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list