- flo.gehrke <flo.gehrke@...> wrote:
>

Here's a simple concept for speedy native sorting of just positive integers that doesn't involve zero-padding and StrSort():

> I would like to remember a discussion on numeric sorting of Oct/Nov 2009 (see message #19834).

>

>

^!SetArray %input%=12;22;5;99;34;2;12;4;6;71;2;43;4;12

;Declare highest anticipated value of an element

^!Set %h%=100; %i%=1

;Prep destination array of empty elements

^!SetArray %sorted%=^$StrFill(";";^%h%)$

;Assign elements to positions equivalent to their values

^!Set %sorted^%input^%i%%%=^%input^%i%%

^!Inc %i%

^!If ^%i%<=^%input0% Skip_-2

;Done deal; just collect sorted integers, e.g.:

^!InsertSelect ^%sorted%

^!SetArray %sorted%=^$GetDocMatchAll(\d+)$

^!Toolbar Undo

^!Info ^%sorted%

- - -

When it's undesirable to paste stuff (as opted for in the last paragraph in order to get results in one fell swoop), here's one of possible alternatives:

;Done deal; get rid of excess semicolons

^!SetArray %sorted%=^$StrReplace(";;";";";"^%sorted%";0;0)$

^!IfMatch ".*?;{2,}.*" "^%sorted%" Skip_-1

;Remove leading semicolon if present

^!IfMatch "\d.*+" "^%sorted%" Skip

^!SetArray %sorted%=^$StrDeleteLeft("^%sorted%";1)$

;Remove ending semicolon if present

^!IfMatch ".*\d" "^%sorted%" Skip

^!SetArray %sorted%=^$StrDeleteRight("^%sorted%";1)$

^!Info ^%sorted% - --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:
>... NoteTab is an interpreter, not a compiler. That means any complex algorithm you build in clip code is going to be much slower, than it would be as a compiled (built-in) function.

I'm still impressed how quick clips run. Reminds me of writing good old Advanced Basic code running on an XT. You know, a 5.1 gogigahertz machine still processes a spreadsheet about as fast as it used to!

> Bubble sort requires (n squared) iterations in the worst-case scenario.

That sounds better. Thanks for the reminder.

> On the other hand, it might be a good exercise to code in clip code. <grin>Just for comparison</grin>.

Gone are the days of the lazy uni student where time was a misspent luxury... <sigh> ... although I can't complain.. I had an entire half a Sunday to sit and relax this week. :)

My current project needed a 'calculate by hand' style multiplication routine to handle ridiculously large numbers. To be honest, I don't mind the 7 seconds it takes to multiply two - one hundred digit -numbers.

Fascinating really and the exciting bit is that we seem to have come full circle and once again the computer is doing exactly what the user wants... without the OOP, "compiler declares headache" syndrome. <smile> </b>

Cheers,

Paul