all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -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! ;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
10 [ 10000 random ] replicate
|
||||
[ "Before: " write . ]
|
||||
[ "Natural: " write [ natural-sort! ] keep . ]
|
||||
[ "Reverse: " write [ [ >=< ] sort! ] keep . ] tri
|
||||
Loading…
Add table
Add a link
Reference in a new issue