Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

An optimist believes we live in the best world possible; a pessimist fears this is true.


devel / comp.lang.lisp / Re: decimal length of +ve integers

SubjectAuthor
* decimal length of +ve integersJames Cloos
+* Re: decimal length of +ve integersLieven Marchand
|`* Re: decimal length of +ve integersKaz Kylheku
| `* Re: decimal length of +ve integersPaul Rubin
|  `- Re: decimal length of +ve integersKaz Kylheku
`- Re: decimal length of +ve integersNicolas Neuss

1
decimal length of +ve integers

<m3mt98kk6y.fsf@carbon.jhcloos.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17207&group=comp.lang.lisp#17207

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: cloos@jhcloos.com (James Cloos)
Newsgroups: comp.lang.lisp
Subject: decimal length of +ve integers
Date: Thu, 03 Nov 2022 13:43:33 -0400
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <m3mt98kk6y.fsf@carbon.jhcloos.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="4ab84e09c640a176f24f1d051f7897d5";
logging-data="1596712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wT8zEX2XY/JgiR7NTY9y+"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:tiEN/3PuCt3xK2jPIx+LHAzDeuA=
sha1:XkdgKX4fOBGau8Otn/8V+vad1kg=
OpenPGP: 0x997A9F17ED7DAEA6; url=https://jhcloos.com/public_key/0x997A9F17ED7DAEA6.asc
OpenPGP-Fingerprint: E9E9 F828 61A4 6EA9 0F2B 63E7 997A 9F17 ED7D AEA6
Copyright: Copyright 2022 James Cloos
Face: iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAACVBMVEX///8ZGXBQKKnCrDQ3
AAAAJElEQVQImWNgQAAXzwQg4SKASgAlXIEEiwsSIYBEcLaAtMEAADJnB+kKcKioAAAAAElFTkSu
QmCC
 by: James Cloos - Thu, 3 Nov 2022 17:43 UTC

does cl offer a better way to do? :

(defun decimal-length (+integer)
(length (format nil "~d" +integer)))

-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 0x997A9F17ED7DAEA6

Re: decimal length of +ve integers

<871qqjop6h.fsf@wyrd.be>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17208&group=comp.lang.lisp#17208

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 03 Nov 2022 18:42:14 +0000
From: mal@wyrd.be (Lieven Marchand)
Newsgroups: comp.lang.lisp
Subject: Re: decimal length of +ve integers
References: <m3mt98kk6y.fsf@carbon.jhcloos.org>
Date: Thu, 03 Nov 2022 19:42:14 +0100
Message-ID: <871qqjop6h.fsf@wyrd.be>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:jo3cmTP0fYP5lqxURyJJI81W23E=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Lines: 13
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-MNEnD6B9MRMskq5O0FO2CHhetUUpdq57tPlEauzatii5eEFxOpngTP0iHbS3xtv1WbERapF12/MYGRl!kN6ZNlE0l8Pa0hjbmaZgeVyXNhSHMggDAPorqgrA2g==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Lieven Marchand - Thu, 3 Nov 2022 18:42 UTC

James Cloos <cloos@jhcloos.com> writes:

> does cl offer a better way to do? :
>
> (defun decimal-length (+integer)
> (length (format nil "~d" +integer)))

One can argue about better but (1+ (floor (log +integer 10))) would also
work.

--
Laat hulle almal sterf. Ek is tevrede om die wêreld te sien brand en die vallende
konings te spot. Ek en my aasdier sal loop op die as van die verwoeste aarde.

Re: decimal length of +ve integers

<20221103173528.413@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17209&group=comp.lang.lisp#17209

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: decimal length of +ve integers
Date: Fri, 4 Nov 2022 00:55:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 95
Message-ID: <20221103173528.413@kylheku.com>
References: <m3mt98kk6y.fsf@carbon.jhcloos.org> <871qqjop6h.fsf@wyrd.be>
Injection-Date: Fri, 4 Nov 2022 00:55:20 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="c63f22f46f2069b6e4338279d38e2543";
logging-data="1668399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Mtx6pmTU7Q6LLYsj2uloqTrbF4ervk08="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Y9cIlqMgJHPhNwe1POEmPg4HQTA=
 by: Kaz Kylheku - Fri, 4 Nov 2022 00:55 UTC

On 2022-11-03, Lieven Marchand <mal@wyrd.be> wrote:
> James Cloos <cloos@jhcloos.com> writes:
>
>> does cl offer a better way to do? :
>>
>> (defun decimal-length (+integer)
>> (length (format nil "~d" +integer)))
>
> One can argue about better but (1+ (floor (log +integer 10))) would also
> work.

Here is another idea. Let's restrict to nonnegative integers.
Or, well, I see that's already implied by the +integer naming.

Further, let's suppose we just need an lower bound on the number of
digits, but one that is fairly tight: say not excessive by more than 1.

To get that we can avoid taking a logarithm of an integer, which could
be a bignum.

We can use integer-length to get the number of binary digits, and
then estimat the decimal digits required to represent that many
binary digits.

There are (/ (log 10) (log 2)) binary digits in a decimal digit,
so we just have to divide by this value and make a little adjustment.
Or let's reciprocate it:

(defconstant %bit-digits% (/ (log 2) (log 10)))

(defun decimal-length (+integer)
(coerce (ceiling (* (integer-length +integer) %bit-digits%)) 'integer))

(loop for i = 3 then (coerce (truncate (* i (sqrt 2))) 'integer)
while (< i 100000000)
do (format t "~s ~s~%" i (decimal-length i)))
3 1
4 1
5 1
7 1
9 2
12 2
16 2
22 2
31 2
43 2
60 2
84 3
118 3
166 3
234 3
330 3
466 3
659 4
931 4
1316 4
1861 4
2631 4
3720 4
5260 4
7438 4
10518 5
14874 5
21035 5
29747 5
42068 5
59493 5
84135 6
118984 6
168268 6
237966 6
336534 6
475930 6
673066 7
951859 7
1346131 7
1903716 7
2692261 7
3807432 7
5384522 7
7614864 7
10769044 8
15229728 8
21538088 8
30459456 8
43076176 8
60918912 8
86152352 9

Floating-point could be eliminated if we use a rational approximation
for the factor.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: decimal length of +ve integers

<87tu3f34gg.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17210&group=comp.lang.lisp#17210

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.lisp
Subject: Re: decimal length of +ve integers
Date: Thu, 03 Nov 2022 18:15:27 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <87tu3f34gg.fsf@nightsong.com>
References: <m3mt98kk6y.fsf@carbon.jhcloos.org> <871qqjop6h.fsf@wyrd.be>
<20221103173528.413@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="0461ae35af174ede71c441fa410727a9";
logging-data="1666534"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+M6WCTR1X5QW00SCvllLK3"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:1OrMnVuOizdEoGam6fB2TuN/+M4=
sha1:B1JT5t3i61+oYulnaf1hQqWgbEU=
 by: Paul Rubin - Fri, 4 Nov 2022 01:15 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:
> (loop for i = 3 then (coerce (truncate (* i (sqrt 2))) 'integer)
> while (< i 100000000)
> do (format t "~s ~s~%" i (decimal-length i)))
> 3 1
> 4 1 ...
> 60918912 8
> 86152352 9

Wait, that last one doesn't look right.

This works for me:

(defun decimal-length (n)
(cond
((< n 0) (1+ (ilen (- n))))
((< n 10) 1)
(t (1+ (ilen (/ n 10))))))

Re: decimal length of +ve integers

<20221103200434.79@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17211&group=comp.lang.lisp#17211

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: decimal length of +ve integers
Date: Fri, 4 Nov 2022 03:07:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20221103200434.79@kylheku.com>
References: <m3mt98kk6y.fsf@carbon.jhcloos.org> <871qqjop6h.fsf@wyrd.be>
<20221103173528.413@kylheku.com> <87tu3f34gg.fsf@nightsong.com>
Injection-Date: Fri, 4 Nov 2022 03:07:43 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="c63f22f46f2069b6e4338279d38e2543";
logging-data="1777284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mB35Ljl75zMBcceGQorQ1/Yi9dNas4EA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:UkZloOFFpqmAUvvxXOSHR3lNNKA=
 by: Kaz Kylheku - Fri, 4 Nov 2022 03:07 UTC

On 2022-11-04, Paul Rubin <no.email@nospam.invalid> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>> (loop for i = 3 then (coerce (truncate (* i (sqrt 2))) 'integer)
>> while (< i 100000000)
>> do (format t "~s ~s~%" i (decimal-length i)))
>> 3 1
>> 4 1 ...
>> 60918912 8
>> 86152352 9
>
> Wait, that last one doesn't look right.

I explained, in not many words, that I bent the requirements: if it
is acceptable to get an upper bound on the numbrer of digits that is not
too excessive (say not by more than one), then this approximate solution
can work.

Like say we wanted to allocate a buffer for the digit string, and didn't
care about an extra byte sometimes.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: decimal length of +ve integers

<864jvf9d3i.fsf@scipolis.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17212&group=comp.lang.lisp#17212

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!oQ1RjrWABcbcby/HXTfRWA.user.46.165.242.75.POSTED!not-for-mail
From: lastname@scipolis.de (Nicolas Neuss)
Newsgroups: comp.lang.lisp
Subject: Re: decimal length of +ve integers
Date: Fri, 04 Nov 2022 12:24:33 +0100
Organization: Aioe.org NNTP Server
Message-ID: <864jvf9d3i.fsf@scipolis.de>
References: <m3mt98kk6y.fsf@carbon.jhcloos.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="28622"; posting-host="oQ1RjrWABcbcby/HXTfRWA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:DYk6EmXzNY8cNsaZktw21JJaZB8=
 by: Nicolas Neuss - Fri, 4 Nov 2022 11:24 UTC

James Cloos <cloos@jhcloos.com> writes:

> does cl offer a better way to do? :
>
> (defun decimal-length (+integer)
> (length (format nil "~d" +integer)))
>
> -JimC

(defun decimal-length (n)
(loop while (plusp n) do
(setf n (floor n 10))
count 1))

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor