is among - problem
Thomas J McGrath III
3mcgrath at adelphia.net
Sat Nov 22 08:08:36 EST 2003
This one I am going to have to test but it is a third completely unique
approach.
It does use the 'is in' operator that Jac was suggesting and it is very
interesting.
That is what I love about scripting, the more people you talk to the
more different solutions you can find to a problem.
Thank you very much,
Der Cubist
On Nov 22, 2003, at 5:14 AM, Cubist at aol.com wrote:
> I'm a bit surprised that no one has brought up the REPLACE command
> in this
> context. "replace WhateverText with empty in WhateverList" will
> *erase* all
> instances of WhateverText from WhateverList in one fell swoop -- no
> need to
> bother with silly repeat loops. Since the original problem specified
> that we're
> dealing with 3-digit numbers, and that we want to nuke all
> permutations of the
> given number, here is some code which should preserve the first
> instance of
> whatever set of 3 digits, and nuke all the other instances as well as
> nuking all
> the permutations of those 3 digits.
>
> ================
>
> put return after DerList -- you'll see why later
> put line 1 of DerList into Fred
>
> -- build list of permutations
> put Fred into George
> put "," & char 1 of Fred & char 3 of Fred & char 2 of Fred after
> George
> put "," & char 2 of Fred & char 1 of Fred & char 3 of Fred after
> George
> put "," & char 2 of Fred & char 3 of Fred & char 1 of Fred after
> George
> put "," & char 3 of Fred & char 1 of Fred & char 2 of Fred after
> George
> put "," & char 3 of Fred & char 2 of Fred & char 1 of Fred after
> George
>
> -- eliminate duplicates from George
> repeat with K1 = 6 down to 2 step -1
> if item K1 of George is in item 1 to (K1 - 1) of George then
> delete item
> K1 of George
> end repeat
>
> if the number of items in George > 1 then
> -- use the REPLACE trick!
> repeat with K1 = 2 to (the number of items in George)
> replace (item K1 of George & return) with empty in George
> -- now d'you see why i appended that return at the start of this
> code?
> end repeat
> end if
>
> -- find the first line which contains Fred
> put the number of lines in char 1 to (offset (Fred,DerList)) of
> DerList
> into DisLine
>
> -- nuke all dupes of Fred
> put line (DisLine + 1) to (the number of lines in DerList) into Zelda
> replace (Fred & return) with empty in Zelda
>
> -- insert the result back into the list
> put Zelda into line (DisLine + 1) to (the number of lines in
> DerList) of
> DerList
>
> ================
>
> Hope this helps...
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
Macintosh PowerBook G-4 OSX 10.3.1, OS 9.2.2, 1.25 GHz, 512MB RAM, Rev
2.1.2
Advanced Media Group
Thomas J McGrath III 2003 3mcgrath at adelphia.net
220 Drake Road, Bethel Park, PA 15102
More information about the use-livecode
mailing list