On 16.12.2010 at 19:29 Uhr -0400 william humphrey apparently wrote:
My math skills are terrible but this is something I can do in excel but
which should also be easy to do with a nested array in livecode. I want to
build a function that returns the numbers that are out of sequence in a list
of numbers. Say you are given (3,4,5,6,6,7,8,9,10,12,13,13,14) and the
function should return:
(1,2,11 - missing)
(6,13 - duplicate)
Can someone please help me write this function?
Thanks in advance.
A quickie:
function getMissingNumbers pNumberList
put empty into vOccurences
repeat for each item vNumber in pNumberList
add 1 to vOccurences[vNumber]
end repeat
get the keys of vOccurences
sort lines of it numeric
put line -1 of it into vLargestNumber
put empty into vMissing
repeat with i=1 to vLargestNumber
if vOccurences[i] is empty then put i & comma after vMissing
end repeat
delete char -1 of vMissing
return vMissing
end getMissingNumbers
function getDuplicateNumbers pNumberList
put empty into vOccurences
repeat for each item vNumber in pNumberList
add 1 to vOccurences[vNumber]
end repeat
get the keys of vOccurences
sort lines of it numeric
put line -1 of it into vLargestNumber
put empty into vDuplicate
repeat with i=1 to vLargestNumber
if vOccurences[i] > 1 then put i & comma after vDuplicate
end repeat
delete char -1 of vDuplicate
return vDuplicate
end getDuplicateNumbers
You can of course combine these functions returning each set of
values in a separate line or as an array. If you actually want to
check for numbers that are out of sequence, the above won't do.
Robert
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode