Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Stinginess with privileges is kindness in disguise. -- Guide to VAX/VMS Security, Sep. 1984


devel / comp.lang.forth / Re: Can Forth count?

SubjectAuthor
* Can Forth count?Robert L.
`- Re: Can Forth count?S Jack

1
Can Forth count?

<t011j8$gbb$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17021&group=comp.lang.forth#17021

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!bvgHpzLNDmR+c2aSW1J/UQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamm...@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.forth
Subject: Can Forth count?
Date: Sun, 6 Mar 2022 01:08:56 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t011j8$gbb$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="16747"; posting-host="bvgHpzLNDmR+c2aSW1J/UQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sun, 6 Mar 2022 01:08 UTC

Determine how many times each string in the list occurs.
Sort the result in descending order.

Gauche Scheme:

(define (count-strings lst)
(define table (make-hash-table 'string=?))
(for-each
(cut hash-table-update! table <> (cut + 1 <>) 0)
lst)
(sort (hash-table->alist table) > cdr))

(count-strings '("foo" "foo" "bar" "zebra"
"u" "w" "u" "xx" "apt" "xx" "get" "climb"
"get" "xx" "tab" "set" "cure"))

===>
(("xx" . 3) ("foo" . 2) ("get" . 2) ("u" . 2) ("w" . 1) ("climb" . 1)
("tab" . 1) ("zebra" . 1) ("apt" . 1) ("bar" . 1) ("set" . 1)
("cure" . 1))

In Forth?

Re: Can Forth count?

<71a725d4-7396-4ce6-9c88-c9fe0dac7bc7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17026&group=comp.lang.forth#17026

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:e43:b0:432:58fa:4cbb with SMTP id o3-20020a0562140e4300b0043258fa4cbbmr4571394qvc.94.1646554199512;
Sun, 06 Mar 2022 00:09:59 -0800 (PST)
X-Received: by 2002:a05:622a:18b:b0:2de:8f67:b3e2 with SMTP id
s11-20020a05622a018b00b002de8f67b3e2mr5332416qtw.104.1646554198660; Sun, 06
Mar 2022 00:09:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 6 Mar 2022 00:09:58 -0800 (PST)
In-Reply-To: <t011j8$gbb$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:790e:70da:4541:696a;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:790e:70da:4541:696a
References: <t011j8$gbb$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <71a725d4-7396-4ce6-9c88-c9fe0dac7bc7n@googlegroups.com>
Subject: Re: Can Forth count?
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sun, 06 Mar 2022 08:09:58 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 73
 by: S Jack - Sun, 6 Mar 2022 08:09 UTC

On Saturday, March 5, 2022 at 7:09:00 PM UTC-6, Robert L. wrote:
> Determine how many times each string in the list occurs.
> Sort the result in descending order.
>
> Gauche Scheme:
>
> (define (count-strings lst)
> (define table (make-hash-table 'string=?))
> (for-each
> (cut hash-table-update! table <> (cut + 1 <>) 0)
> lst)
> (sort (hash-table->alist table) > cdr))
>
> (count-strings '("foo" "foo" "bar" "zebra"
> "u" "w" "u" "xx" "apt" "xx" "get" "climb"
> "get" "xx" "tab" "set" "cure"))
>
> ===>
> (("xx" . 3) ("foo" . 2) ("get" . 2) ("u" . 2) ("w" . 1) ("climb" . 1)
> ("tab" . 1) ("zebra" . 1) ("apt" . 1) ("bar" . 1) ("set" . 1)
> ("cure" . 1))
>
>
> In Forth?
:) frogd
ELF32X86_64 Frog Version 1.0d

"job" /go
: string+count ( -- s )
tmp2 @ pad s+
bl c+
tmp@ ntos s+
"\n" s+
;

asc ; ' s dfa !

"foo" "foo" "bar" "zebra" "u" "w" "u" "xx" "apt"
"xx" "get" "climb" "get" "xx" "tab" "set" "cure"
s echo -n "; mpad sas
{ begin depth 1 > while swap s+ "\n" s+ repeat } run1
s "|sort; s+
/sys:send
{ pad 32 erase 0 tmp!
begin
\n split
dup while
2dup pad gscmp if ( new string)
tmp@ if string+count tmp2 ! fi
pad gts 1 tmp!
ii ( same string)
2drop 1 tmp +!
fi
repeat 4drop
string+count '"|sort -rk2' s+
} is hr:rrx
s echo "; mpad sas tmp2 !
cr hr:rrx /sys
xx 3
u 2
get 2
foo 2
zebra 1
w 1
tab 1
set 1
cure 1
climb 1
bar 1
apt 1

ok
--
me

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor