@ Raul

> The J way of implementing merge might be /:~@,

I agree, but I want to avoid the use of /:   :-) 

I already tried your variant myself:

    mergeSort1 =: merge & $: &>/ @ split ^: (1 < #) ^:_

but it is for arguments of length 3e3 10x slower (?), so I dropped that one.

M=. 3e3 ?...@#1e3

   ts 'mergeSort1 M'
2.970816 14839488
   ts 'mergeSort M'
0.324539 14807488

@ Viktor

> It's not always ridiculous
I meant compared to my implementation of 'merge'.

>   a =. {...@] , (merge1 }.)
>   merge1=: a...@.(>&{.)`,@.(*...@*&#)
>   mergeSortV =: merge1 & $: &>/ @ split ` ] @. (1>:#)

   mergeSortV 1 5 7 3 8 2 6 9 4
1 4 8 7 6 5 2 3 9

??

change to a nand function e.g. (or flip the outer gerund):
merge1=: a...@.(>&{.)`,@.(-...@*@*&#)

   mergeSortV 1 5 7 3 8 2 6 9 4
1 2 3 4 5 6 7 8 9

M=. 3e3 ?...@#1e3

   mergeSortV M
|stack error: merge1
|       mergeSortV M

Return to not splitting up the merge verb:

merge1=: ({...@] , ($: }.))~` ({...@] , ($: }.)) @.(>&{.)`,@.(-...@*@*&#)

   mergeSortV M
0 0 0 0 0 0 1 1 1 1 1 2 3 3 .....


FYI

Thank you for your replies.



-- 
Met vriendelijke groet,
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to