all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,23 @@
USING: fry kernel locals math math.order sequences
sequences.private ;
IN: rosetta.bubble
<PRIVATE
:: ?exchange ( i seq quot -- ? )
i i 1 + [ seq nth-unsafe ] bi@ quot call +gt+ = :> doit?
doit? [ i i 1 + seq exchange ] when
doit? ; inline
: 1pass ( seq quot -- ? )
[ [ length 1 - iota ] keep ] dip
'[ _ _ ?exchange ] [ or ] map-reduce ; inline
PRIVATE>
: sort! ( seq quot -- )
over empty?
[ 2drop ] [ '[ _ _ 1pass ] loop ] if ; inline
: natural-sort! ( seq -- )
[ <=> ] sort! ;

View file

@ -0,0 +1,4 @@
10 [ 10000 random ] replicate
[ "Before: " write . ]
[ "Natural: " write [ natural-sort! ] keep . ]
[ "Reverse: " write [ [ >=< ] sort! ] keep . ] tri