Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
That would work until some idiot (like me) tried to sort a list containing asterisks. Bob On Jul 2, 2010, at 5:50 AM, Michael Kann wrote: > Hugh, thanks for providing a fun and educational challenge -- and organizing > the results. I woke up with an idea. Can you time my late entry? > Thanks. > > Mike > > - > -- I think the script is pretty > -- self-explanatory > - > > > on mouseUp > put fld 1 into v -- original data > set the itemDel to "*" > > repeat with k = 0 to 9 > replace k with "*"&k in v > end repeat > > repeat for each line k in v > replace "*" with "" in item 2 to -1 of k > put k & cr after h > end repeat > delete last char of h > > sort h numeric by item 2 of each > sort h by item 1 of each > replace "*" with "" in h > > put h into fld 2 -- output > end mouseUp > > --------- > > --- On Fri, 7/2/10, FlexibleLearning wrote: > >> From: FlexibleLearning >> Subject: Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION >> To: use-revolution@lists.runrev.com >> Date: Friday, July 2, 2010, 1:19 AM >> I made an inexcusable error when >> applying the solutions in the benchtests. >> When adjusting Mike's solution to handle commas in the list >> I omitted to >> adjust the itemDel. The corrected solution is below. >> >> As a result, Mike's solution is not only very fast, but >> also sub-sorts the >> alpha component and handles mixed suffix components (which >> is very cool). >> However, as pointed out, it cannot handle alpha-only list >> items. Dave's >> solution can handle lists with or without numbers, but the >> sort order is >> inexact. >> >> Using the insights of both solutions, I have based a >> composite solution on >> Mike's routine adjusted with the flexibility Dave's >> routine. It has Mike's >> speed and ability to sort mixed suffixes, but includes >> Dave's ability to >> sort mixed alpha-only and alphanumeric lists. I think this >> provides the best >> of everything for a generic library function... >> >> function sortMe5 pList >> --| Hugh Senior >> --| Based on a solution by Mike Bonner >> set the itemDel to numtochar(8) >> repeat for each line theLine in pList >> if >> matchchunk(theLine,"([a-zA-Z\s]\d)",theChar,theEnd) then >> put numtochar(8) after char theChar of >> theLine >> else put numtochar(8) after theLine >> put theLine & CR after tTemp >> end repeat >> delete last char of tTemp >> sort lines of tTemp numeric by item 2 of each >> sort lines of tTemp by item 1 of each >> replace numtochar(8) with "" in tTemp >> return tTemp >> end sortMe5 >> >> a 1 >> b20 >> a 20 >> a 2 >> b10 >> a 3 >> b3 >> a 1a >> b2 >> a 10 >> b1a >> d >> c >> b >> a >> >> gives... >> >> a >> a 1 >> a 1a >> a 2 >> a 3 >> a 10 >> a 20 >> b >> b1a >> b2 >> b3 >> b10 >> b20 >> c >> d >> >> Prior Work... >> >> function sortMe1 pVar >> --| Mike Bonner >> set the itemDel to numtochar(8) >> repeat for each line theLIne in PVar >> get matchchunk(theLine,"([a-zA-Z\s]\d)" , >> theChar,theEnd ) >> put numtochar(8) after char theChar of >> theLine >> put theLine & return after tTemp >> end repeat >> delete the last char of tTemp >> sort lines of tTemp ascending numeric by item 2 of >> each >> sort lines of tTemp ascending by item 1 of each >> replace numtochar(8) with empty in tTemp >> return tTemp >> end sortMe1 >> >> function sortMe2 tData >> --| Dave Cragg >> set the itemDel to numtochar(8) >> put "(^.*?)([0-9]*$)" into tRE >> put "" into tData2 >> repeat for each line tLine in tData >> get matchText(tLine, tRE, tS, tNum) >> put tS & numtochar(8) & tNum & cr >> after tData2 >> end repeat >> sort lines of tData2 numeric by item -1 of each >> sort lines of tData2 by item 1 of each >> put "" into tData3 >> repeat for each line tLine in tData2 >> put item 1 to -2 of tLine & item -1 of >> tLine & cr after tData3 >> end repeat >> return tData3 >> end sortMe2 >> >> >> /H >> >> ___ >> use-revolution mailing list >> use-revolution@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage >> your subscription preferences: >> http://lists.runrev.com/mailman/listinfo/use-revolution >> > > > > ___ > use-revolution mailing list > use-revolution@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-revolution ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
BTW this is going straight into my Shamelessly Exploit folder. Bob On Jul 1, 2010, at 11:19 PM, FlexibleLearning wrote: > I made an inexcusable error when applying the solutions in the benchtests. > When adjusting Mike's solution to handle commas in the list I omitted to > adjust the itemDel. The corrected solution is below. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
That's beautiful stuff! See? Humanity CAN work together for the common good! Bob On Jul 1, 2010, at 11:19 PM, FlexibleLearning wrote: > I made an inexcusable error when applying the solutions in the benchtests. > When adjusting Mike's solution to handle commas in the list I omitted to > adjust the itemDel. The corrected solution is below. > > As a result, Mike's solution is not only very fast, but also sub-sorts the > alpha component and handles mixed suffix components (which is very cool). > However, as pointed out, it cannot handle alpha-only list items. Dave's > solution can handle lists with or without numbers, but the sort order is > inexact. > > Using the insights of both solutions, I have based a composite solution on > Mike's routine adjusted with the flexibility Dave's routine. It has Mike's > speed and ability to sort mixed suffixes, but includes Dave's ability to > sort mixed alpha-only and alphanumeric lists. I think this provides the best > of everything for a generic library function... > > function sortMe5 pList > --| Hugh Senior > --| Based on a solution by Mike Bonner > set the itemDel to numtochar(8) > repeat for each line theLine in pList >if matchchunk(theLine,"([a-zA-Z\s]\d)",theChar,theEnd) then > put numtochar(8) after char theChar of theLine >else put numtochar(8) after theLine >put theLine & CR after tTemp > end repeat > delete last char of tTemp > sort lines of tTemp numeric by item 2 of each > sort lines of tTemp by item 1 of each > replace numtochar(8) with "" in tTemp > return tTemp > end sortMe5 > > a 1 > b20 > a 20 > a 2 > b10 > a 3 > b3 > a 1a > b2 > a 10 > b1a > d > c > b > a > > gives... > > a > a 1 > a 1a > a 2 > a 3 > a 10 > a 20 > b > b1a > b2 > b3 > b10 > b20 > c > d > > Prior Work... > > function sortMe1 pVar > --| Mike Bonner > set the itemDel to numtochar(8) > repeat for each line theLIne in PVar >get matchchunk(theLine,"([a-zA-Z\s]\d)" , theChar,theEnd ) >put numtochar(8) after char theChar of theLine >put theLine & return after tTemp > end repeat > delete the last char of tTemp > sort lines of tTemp ascending numeric by item 2 of each > sort lines of tTemp ascending by item 1 of each > replace numtochar(8) with empty in tTemp > return tTemp > end sortMe1 > > function sortMe2 tData > --| Dave Cragg > set the itemDel to numtochar(8) > put "(^.*?)([0-9]*$)" into tRE > put "" into tData2 > repeat for each line tLine in tData >get matchText(tLine, tRE, tS, tNum) >put tS & numtochar(8) & tNum & cr after tData2 > end repeat > sort lines of tData2 numeric by item -1 of each > sort lines of tData2 by item 1 of each > put "" into tData3 > repeat for each line tLine in tData2 >put item 1 to -2 of tLine & item -1 of tLine & cr after tData3 > end repeat > return tData3 > end sortMe2 > > > /H > > ___ > use-revolution mailing list > use-revolution@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-revolution ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
Hugh, thanks for providing a fun and educational challenge -- and organizing the results. I woke up with an idea. Can you time my late entry? Thanks. Mike - -- I think the script is pretty -- self-explanatory - on mouseUp put fld 1 into v -- original data set the itemDel to "*" repeat with k = 0 to 9 replace k with "*"&k in v end repeat repeat for each line k in v replace "*" with "" in item 2 to -1 of k put k & cr after h end repeat delete last char of h sort h numeric by item 2 of each sort h by item 1 of each replace "*" with "" in h put h into fld 2 -- output end mouseUp - --- On Fri, 7/2/10, FlexibleLearning wrote: > From: FlexibleLearning > Subject: Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION > To: use-revolution@lists.runrev.com > Date: Friday, July 2, 2010, 1:19 AM > I made an inexcusable error when > applying the solutions in the benchtests. > When adjusting Mike's solution to handle commas in the list > I omitted to > adjust the itemDel. The corrected solution is below. > > As a result, Mike's solution is not only very fast, but > also sub-sorts the > alpha component and handles mixed suffix components (which > is very cool). > However, as pointed out, it cannot handle alpha-only list > items. Dave's > solution can handle lists with or without numbers, but the > sort order is > inexact. > > Using the insights of both solutions, I have based a > composite solution on > Mike's routine adjusted with the flexibility Dave's > routine. It has Mike's > speed and ability to sort mixed suffixes, but includes > Dave's ability to > sort mixed alpha-only and alphanumeric lists. I think this > provides the best > of everything for a generic library function... > > function sortMe5 pList > --| Hugh Senior > --| Based on a solution by Mike Bonner > set the itemDel to numtochar(8) > repeat for each line theLine in pList > if > matchchunk(theLine,"([a-zA-Z\s]\d)",theChar,theEnd) then > put numtochar(8) after char theChar of > theLine > else put numtochar(8) after theLine > put theLine & CR after tTemp > end repeat > delete last char of tTemp > sort lines of tTemp numeric by item 2 of each > sort lines of tTemp by item 1 of each > replace numtochar(8) with "" in tTemp > return tTemp > end sortMe5 > > a 1 > b20 > a 20 > a 2 > b10 > a 3 > b3 > a 1a > b2 > a 10 > b1a > d > c > b > a > > gives... > > a > a 1 > a 1a > a 2 > a 3 > a 10 > a 20 > b > b1a > b2 > b3 > b10 > b20 > c > d > > Prior Work... > > function sortMe1 pVar > --| Mike Bonner > set the itemDel to numtochar(8) > repeat for each line theLIne in PVar > get matchchunk(theLine,"([a-zA-Z\s]\d)" , > theChar,theEnd ) > put numtochar(8) after char theChar of > theLine > put theLine & return after tTemp > end repeat > delete the last char of tTemp > sort lines of tTemp ascending numeric by item 2 of > each > sort lines of tTemp ascending by item 1 of each > replace numtochar(8) with empty in tTemp > return tTemp > end sortMe1 > > function sortMe2 tData > --| Dave Cragg > set the itemDel to numtochar(8) > put "(^.*?)([0-9]*$)" into tRE > put "" into tData2 > repeat for each line tLine in tData > get matchText(tLine, tRE, tS, tNum) > put tS & numtochar(8) & tNum & cr > after tData2 > end repeat > sort lines of tData2 numeric by item -1 of each > sort lines of tData2 by item 1 of each > put "" into tData3 > repeat for each line tLine in tData2 > put item 1 to -2 of tLine & item -1 of > tLine & cr after tData3 > end repeat > return tData3 > end sortMe2 > > > /H > > ___ > use-revolution mailing list > use-revolution@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage > your subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-revolution > ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
Thanks for keeping us up to date, Hugh. Of course, another solution might be to write a polite letter to whoever is giving you this data suggesting they collect it differently in the first place. :-) Cheers Dave___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: Intelligent sorting: A bit of a poser RESULTS CORRECTION
I made an inexcusable error when applying the solutions in the benchtests. When adjusting Mike's solution to handle commas in the list I omitted to adjust the itemDel. The corrected solution is below. As a result, Mike's solution is not only very fast, but also sub-sorts the alpha component and handles mixed suffix components (which is very cool). However, as pointed out, it cannot handle alpha-only list items. Dave's solution can handle lists with or without numbers, but the sort order is inexact. Using the insights of both solutions, I have based a composite solution on Mike's routine adjusted with the flexibility Dave's routine. It has Mike's speed and ability to sort mixed suffixes, but includes Dave's ability to sort mixed alpha-only and alphanumeric lists. I think this provides the best of everything for a generic library function... function sortMe5 pList --| Hugh Senior --| Based on a solution by Mike Bonner set the itemDel to numtochar(8) repeat for each line theLine in pList if matchchunk(theLine,"([a-zA-Z\s]\d)",theChar,theEnd) then put numtochar(8) after char theChar of theLine else put numtochar(8) after theLine put theLine & CR after tTemp end repeat delete last char of tTemp sort lines of tTemp numeric by item 2 of each sort lines of tTemp by item 1 of each replace numtochar(8) with "" in tTemp return tTemp end sortMe5 a 1 b20 a 20 a 2 b10 a 3 b3 a 1a b2 a 10 b1a d c b a gives... a a 1 a 1a a 2 a 3 a 10 a 20 b b1a b2 b3 b10 b20 c d Prior Work... function sortMe1 pVar --| Mike Bonner set the itemDel to numtochar(8) repeat for each line theLIne in PVar get matchchunk(theLine,"([a-zA-Z\s]\d)" , theChar,theEnd ) put numtochar(8) after char theChar of theLine put theLine & return after tTemp end repeat delete the last char of tTemp sort lines of tTemp ascending numeric by item 2 of each sort lines of tTemp ascending by item 1 of each replace numtochar(8) with empty in tTemp return tTemp end sortMe1 function sortMe2 tData --| Dave Cragg set the itemDel to numtochar(8) put "(^.*?)([0-9]*$)" into tRE put "" into tData2 repeat for each line tLine in tData get matchText(tLine, tRE, tS, tNum) put tS & numtochar(8) & tNum & cr after tData2 end repeat sort lines of tData2 numeric by item -1 of each sort lines of tData2 by item 1 of each put "" into tData3 repeat for each line tLine in tData2 put item 1 to -2 of tLine & item -1 of tLine & cr after tData3 end repeat return tData3 end sortMe2 /H ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution