That's a very clean and simple solution, Ken. I've enjoyed looking at all the methods people have used for this simple task. I'd go with yours if speed wasn't an issue - that is, the lengths of data were about as long as the sample and not a megabyte or more of the stuff.
I wrote mine with speed in mind. It makes only one pass through the of the data (1..N+number of dupes), despite the three repeat structures in it. ~ Chris Innanen ~ Nonsanity On Tue, Dec 21, 2010 at 9:44 PM, Ken Ray <[email protected]> wrote: > I know I'm kind of late, but here's another way to accomplish the same > thing > (it's also a bit shorter): > > on mouseUp > put "3,4,5,6,6,7,8,9,10,12,13,13,14" into tData > put MissingAndDupes(tData) into tResult > -- line 1 of tResult will be empty or have a list of missing numbers > -- line 2 of tResult will be empty or have a list of duped numbers > end mouseUp > > function MissingAndDupes pData > repeat for each item tItem in pData > add 1 to tCount[tItem] > end repeat > repeat with x = 1 to max(pData) > if tCount[x] = "" then put (x & ",") after tMissing > if tCount[x] > 1 then put (x & ",") after tDupes > end repeat > delete char -1 of tMissing > delete char -1 of tDupes > return tMissing & cr & tDupes > end MissingAndDupes > > Ken > > On 12/17/10 1:47 PM, "william humphrey" <[email protected]> > wrote: > > > That's exactly what I did. A day doesn't go by that I find another way to > > make a mistake. > > > > Thanks for all your help. > > > > On Fri, Dec 17, 2010 at 3:00 PM, Robert Brenstein <[email protected]> > wrote: > > > >> On 16.12.2010 at 20:36 Uhr -0400 william humphrey apparently wrote: > >> > >>> 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 > >>> > >>> this returns a sequential list of all numbers, not just the missing > >>> numbers > >>> > >> > >> Just tested this and it works for me. May be you passed the data as > >> multiple parameters instead of one. I mean sth like > >> > >> answer getMissingNumbers(3,4,5,6,6,7,8,9,10,12,13,13,14) > >> > >> instead of > >> > >> answer getMissingNumbers("3,4,5,6,6,7,8,9,10,12,13,13,14") > >> > >> This algorithm makes no assumption on the order of data except that it > >> should contain numbers from 1 to the largest number in the set. Their > order > >> or repetition are irrelevant. > >> > >> > >> Robert > >> > >> _______________________________________________ > >> use-livecode mailing list > >> [email protected] > >> Please visit this url to subscribe, unsubscribe and manage your > >> subscription preferences: > >> http://lists.runrev.com/mailman/listinfo/use-livecode > >> > > > > > > Ken Ray > Sons of Thunder Software, Inc. > Email: [email protected] > Web Site: http://www.sonsothunder.com/ > > > > _______________________________________________ > use-livecode mailing list > [email protected] > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > _______________________________________________ use-livecode mailing list [email protected] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
