- --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
>

Here is something I played with after digesting your code, Flo: an entertaining take on proper numeric sorting, without a lag of firing an external app though. It takes an array of numbers delimited with a (standard) semicolon. As is, it provides stock NT accuracy to the second decimal, but it can be set to one's liking with the variable %dec%. With its current algorithm it sorts and deduplicates smaller arrays (of about 200 elements) with a sub-second performance on my comp.

> However, it's an efficient work-around for me to use that DOS-tool EVAL.EXE I mentioned in 2009. You still can download it from

>

> http://tp.lc.ehu.es/jma/msdos.html

>

> My proposal was to use that tool with the following clips. Start with...

>

>

Somewhere in a parent clip:

^!SetArray %ar%=5.76;-2;5;2;4;1.75;1;-10;5;4;5.43;4;4;0.02;401;0;4

^!SetArray %ar%=^$SortNumArray(^%ar%)$

^!Info ^%ar%

And the function itself:

H="SortNumArray"

;Surround input with semicolons (to aid later replacements)

^!SetArray %in%=;^&;

;Adjust only %dec% (desired decimal accuracy from 0 to whatever)

^!Set %dec%=2; %i%=2

;Append decimals where absent

^!Set %in^%i%%=^$Calc(^%in^%i%%;^%dec%)$

^!Inc %i%

^!If ^%i%<^%in0% Skip_-2

:Find_Smallest

;Second element (the first is empty!) and index of third

^!Set %min%=^%in2%; %i%=3

;Get the smallest value iterating through pairs of elements

^!Set %min%=^$Calc(MIN(^%min%;^%in^%i%%);^%dec%)$

^!Inc %i%

^!If ^%i%<^%in0% Skip_-2

;Drop located value in the new array-to-be

^!Append %res%=;^%min%

;Remove located value(s) from the input array

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

^!IfMatch ".*?;^%min%;.*" "^%in%" Skip_-1

;Start another walk-through if at least four elements remain

^!If ^%in0%>3 Find_Smallest

;Check for the possibility of only two empty elements remaining

^!IfEmpty ^%in2% Skip

;Get the last value

^!Append %res%=;^%in2%

;Remove leading semicolon and set the results array

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

^!Result ^%res%

^!Set %in%=; %dec%=; %i%=; %min%=; %res%= - --- 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