Gnome Sort in Redcode





1
Date Submitted Tue. Jan. 15th, 2008 7:56 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. Speed increase of .5x^2-2.5x over version 1.

; x elements sorted in min (2x-1), max ((9x^2-7x)/2) cycles

          org    inner

outer     mov    }p,             temp
p         mov    FIRST+LENGTH-1, {p
          nop    >y,             }p
          mov    temp,           }p
          sne    y,              #LENGTH
          nop    <y,             {p
inner     slt    *p,             {p
y         djn    inner,          #LENGTH-1
          jmn    outer,          y
 

John Metcalf

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

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Beginner impomatic

Votes Down