Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #56694
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | .Re: ANSI Common Lisp, Page 56, Problem 3 |
| Date | 2017-04-04 11:10 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <obvuv2$nve$1@gioia.aioe.org> (permalink) |
Kaz Kylheku wrote:
> On 2016-08-30, Steve Graham <solitary.wanderer52@gmail.com> wrote:
> > The problem states:
> >
> > Define a function that takes a list and returns a list indicating the
> > number of times each (eql) element appears, sorted from most common
> > element to least common
>
> $ txr
> This is the TXR Lisp interactive listener of TXR 147.
> Use the :quit command or type Ctrl-D on empty line to exit.
> 1> [group-by identity '(a a b a c b c c a a d e)]
> #H(() (e (e)) (d (d)) (a (a a a a a)) (c (c c c)) (b (b b)))
> 2> [hash-update [group-by identity '(a a b a c b c c a a d e)] length]
> #H(() (e 1) (d 1) (a 5) (c 3) (b 2))
> 3> (hash-pairs [hash-update [group-by identity '(a a b a c b c c a a d
> e)] length])
> ((e 1) (d 1) (a 5) (c 3) (b 2))
> 4> [sort (hash-pairs [hash-update [group-by identity '(a a b a c b c c
> a a d e)] length]) > second]
> ((a 5) (c 3) (b 2) (d 1) (e 1))
Ruby:
%w(a a b a c b c c a a d e).group_by{|x|x}.map{|k,v|[k,v.size]}.
sort_by{|k,v|-v}
==>[["a", 5], ["c", 3], ["b", 2], ["d", 1], ["e", 1]]
In Forth?
--
One of [the Zionists'] streams of output ... tells everyone else they should
mix together ...; and the other stream of output is ... for internal
consumption, and that says an entirely different and much more healthy thing:
that Jews should intermarry with other Jews....
--- Mark Collett (archive.org/details/Duke.20161104)
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
.Re: ANSI Common Lisp, Page 56, Problem 3 "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-04 11:10 +0000
csiph-web