Gnome Sort in Redcode





2
Date Submitted Mon. Jan. 7th, 2008 7:49 AM
Revision 1 of 1
Beginner impomatic
Tags corewar | redcode | sort
Comments 0 comments
An implementation of Gnome Sort in 9 lines of Redcode. Smaller and faster than Bubble Sort.

; x elements sorted in min (2x-1), max (5x^2-6x+2) cycles

     org    loop

p    mov    temp,              FIRST+LENGTH-1
     seq    l,                 #LENGTH-1
     nop    >l,                >p
loop slt    @p,                <p
l    djn    loop,              #LENGTH-1
     jmz    go+1,              l
     mov    >p,                temp
     mov    @p,                <p
go   jmp    p,                 >p
 

John Metcalf

corewar.co.uk
--
http://corewar.co.uk

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Beginner impomatic
Helper mceppi

Votes Down