function problem4 pList
   local tLength
   put 0 into tLength
   repeat for each item tItem in pList
      put max(the number of chars in tItem, tLength) into tLength
   end repeat
sort items of pList ascending numeric by the number of chars in each
   sort items of pList descending text by problem4_pad(each, tLength)
   replace comma with empty in pList
   return pList
end problem4


This fails on 43,434 -- it returns 43434, but should return 43443

Good catch. In which case, I wonder if there is a way to do it with two padded sorts rather than having a custom comparator which checks pairwise which of AB / BA is greater.

I was trying to find a way to do it using the sort primitives rather than having to write my own sort with a custom comparison routine. As it seemed slightly preferable: you have to prove that your comparator is transitive (A < B, B < C => A < C), which isn't entirely obvious in this instance I don't think.

--
Mark Waddingham ~ [email protected] ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
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

Reply via email to