J: Bubble Sort (2) Roger&Ken 
Author Message
 J: Bubble Sort (2) Roger&Ken

J: Bubble Sort (2)  Roger&Ken

(I'have sent again this posting, because the news server
 of my provider chrashed.)

When I asked Roger Hui, if he would know a shorter solution for bubble
sort, he answered:

Quote:
> As a matter of fact, yes.








r7 =:                                 /:~  NB. ha ha

<

It was quite interesting for me to work through the simplifications.
Especially the use of C. surprised me.

But not enough, Ken Iverson had also a couple of expressions:


  k1=:       ((>{.)|.,)/^:_

Roger Hui:

Quote:
> The first k0 uses the primitive sort /:~ on two elements.
> The second k1 is my favorite.  It engenders exactly the

> but is shorter still and more transparent, and re-introduces
> the rotate |. that you used in your original solution.

The main difference between BS2 and r6 is, that r6 and also k1
move a leading number, which is greater than the following,
to the end of the list.

   ] list=: ?10$15        
7 12 0 0 7 10 0 5 1 6


   g/^:(i.10) list          NB. g insert to the power 0 1 2...
7 12 0 0 7 10  0  5  1  6
0  0 0 1 6  5 10  7 12  7
0  0 0 1 5  7  7 12 10  6
0  0 0 1 5  6 10 12  7  7
0  0 0 1 5  6  7  7 12 10
0  0 0 1 5  6  7  7 10 12
0  0 0 1 5  6  7  7 10 12
...  


   JoinSwitch/^:(i.10) list
7 12  0  0  7 10  0  5  1  6
0  7 12  0  0  7 10  1  5  6
0  0  7 12  0  1  7 10  5  6
0  0  0  7 12  1  5  7 10  6
0  0  0  1  7 12  5  6  7 10
0  0  0  1  5  7 12  6  7 10
0  0  0  1  5  6  7 12  7 10
0  0  0  1  5  6  7  7 12 10
0  0  0  1  5  6  7  7 10 12
0  0  0  1  5  6  7  7 10 12

JoHo :)



Tue, 15 Jun 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. NYSIGAPL presents Ken Iverson & Roger Hui

2. Bubble sort/Selection sort help neded.

3. bubble sort

4. J: Bubble Sort (1)

5. Bubble sort in Haskell

6. Need Help with Bubble Sort in Haskell

7. Only Bubble Sort ??

8. REXX Bubble sort

9. RECURSIVE BUBBLE SORT

10. BASIC BUBBLE SORT AND FIBONACCI HELP

11. bubble sort in assembly

12. Bubble Sort

 

 
Powered by phpBB® Forum Software