Deutsch   English   Français   Italiano  
<67301d2f$0$12913$426a34cc@news.free.fr>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!2.eu.feeder.erje.net!feeder.erje.net!fdn.fr!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp4-1.free.fr!not-for-mail
Date: Sun, 10 Nov 2024 03:40:46 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: =?UTF-8?Q?Re=3A_Le_calcul_de_la_racine_carr=C3=A9=2E=2E=2E_pour_des?=
 =?UTF-8?Q?_nuls_=3A=29?=
Newsgroups: fr.sci.maths
References: <672bcce0$0$28508$426a74cc@news.free.fr>
 <vggpas$b9p$1@cabale.usenet-fr.net> <vggrin$29gqi$1@dont-email.me>
 <672ce7d7$0$12934$426a74cc@news.free.fr> <vgirti$2nvn9$1@dont-email.me>
 <vgkk1k$2i8l$1@cabale.usenet-fr.net> <vgko9b$35kqs$1@dont-email.me>
 <672ea1f1$0$16817$426a34cc@news.free.fr> <vgngar$3oc57$2@dont-email.me>
 <vgnium$197m$1@cabale.usenet-fr.net> <vgnkt6$3ph8l$1@dont-email.me>
 <672f8598$0$11455$426a74cc@news.free.fr>
 <672fac55$0$16825$426a34cc@news.free.fr>
Content-Language: fr
From: Samuel Devulder <samuel.devulder@laposte.net.inalid>
In-Reply-To: <672fac55$0$16825$426a34cc@news.free.fr>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Antivirus: Avast (VPS 241109-4, 9/11/2024), Outbound message
X-Antivirus-Status: Clean
Lines: 73
Message-ID: <67301d2f$0$12913$426a34cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 10 Nov 2024 03:40:47 CET
NNTP-Posting-Host: 88.167.72.245
X-Trace: 1731206447 news-4.free.fr 12913 88.167.72.245:18811
X-Complaints-To: abuse@proxad.net
Bytes: 3716

Le 09/11/2024 à 19:39, Michel Talon a écrit :
> Voici le programme:
> 
> (defun print-bizarre-squares (N str)
>    (let ((k 1) (l 10))
>      (dotimes (i N 'done)
>        (let ((j (* i i)))
>           (when (<= l j)
>             (incf k)
>             (setq l (* 10 l)))
>          ;; Here 10^(k-1) <= j < 10^k, j has k digits
>          (if (evenp k) (test-if-bizarre i j  (expt 10 (/ k 2)) str))))))
> 
> (defun test-if-bizarre (i j l str)
>    (multiple-value-bind (a b) (floor (/ j l))
>      (if (= i (+ a (* l b))) (format str  " ~7d      ~d ~%" i j))))
> 
> (defparameter N (expt 10 7)) ; 10^7
> (with-open-file (str "list-of-bizarre" :direction :output :if- 
> exists :supersede)
>    (time (print-bizarre-squares N str)))

Quelque part c'est moyennement lisible(*) par rapport à cet version plus 
"naturelle" du point de vue algorithmique :

----8<-------------------------------------
i = 0
n = 1
p = 1
q = 10
repeat
   n = n + 1
   if n>=q then
     p = q
     q = q*10
   end
   m = n*n
   a = math.floor(m / q)
   b = math.floor(m % q)
   if a+b==n and a>=p then
     i = i + 1
     print(i, n, m)
   end
until n > 1E7
----8<-------------------------------------

Qui est directement interprétable par Lua et qui donne la même liste de 
45 nombres en même pas deux secondes dans un browser web.

A noter que la condition "a>=p" évite de tomber sur des nombres où l'on 
a besoin du zero implicite devant m=n² pour avoir un découpage plus 
naturel. Si on retire cette condition, on tombe sur ces 10 solutions 
supplémentaires non trouvé par le programme Lisp amenant à un total de 
55 carrés bizarres <= 1E7.

1	297	88209       (297 = 088 + 209)
2	2223	4941729    (2223 = 0494 + 1729)
3	2728	7441984         etc.
4	17344	300814336
5	22222	493817284
6	142857	20408122449
7	148149	21948126201
8	181819	33058148761
9	187110	35010152100
10	208495	43470165025

Pour expérimenter par soi-même: https://onecompiler.com/lua/42xp2gahe

sam.

____
(*) lisp = Lost In Stupid Parentheses
          = Lots of Irritating Superfluous Parentheses