Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #24150

Re: how to osrt 5 numbers

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Re: how to osrt 5 numbers
Date 2013-07-04 10:37 +0000
Organization A noiseless patient Spider
Message-ID <kr3j8d$nvh$1@dont-email.me> (permalink)
References <b58af4d3-e05e-43bf-b867-fcf763655bf3@googlegroups.com> <kgoipn01jja@enews2.newsguy.com> <kpfcb7$958$1@dont-email.me>

Show all headers | View raw


WJ wrote:

> WJ wrote:
> 
> > the_gavino_himself wrote:
> > 
> > > 5 3 33 22 333  smallest to largest
> > > 
> > > I have not mastered shallow stack!
> > > 
> > > How is this done?
> > 
> > Factor:
> > 
> > USE: make
> > 
> > : sort5 ( a b c d e -- seq )
> >   ! Move the numbers into a sequence.
> >   [ , , , , , ] { } make
> >   [ <=> ] sort ;
> 
> Ruby:
> 
> [5, 3, 33, 22, 333].sort
>     ==>[3, 5, 22, 33, 333]
> 
> [5, 3, 33, 22, 333].sort_by{|n| -n}
>     ==>[333, 33, 22, 5, 3]

Clojure:

user=> (sort [5, 3, 33, 22, 333])
(3 5 22 33 333)
user=> (sort-by - [5, 3, 33, 22, 333])
(333 33 22 5 3)
user=> (sort-by - [5 3 33 22 333])
(333 33 22 5 3)

user=> (sort-by odd? [5 3 44 33 22 333 66])
(44 22 66 5 3 33 333)

Back to comp.lang.forth | Previous | Next | Find similar


Thread

Re: how to osrt 5 numbers "WJ" <w_a_x_man@yahoo.com> - 2013-07-04 10:37 +0000

csiph-web