Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <87zgj7xg89.fsf@universite-de-strasbourg.fr.invalid>
Deutsch   English   Français   Italiano  
<87zgj7xg89.fsf@universite-de-strasbourg.fr.invalid>

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

Path: ...!news.mixmin.net!aioe.org!K7PIs9tCGQ+WHJa7e6BylQ.user.46.165.242.75.POSTED!not-for-mail
From: Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid>
Newsgroups: fr.comp.lang.python
Subject: Re: Autre exercice : calculer la somme de x chiffres.
Date: Tue, 24 May 2022 14:33:26 +0200
Organization: =?utf-8?Q?Universit=C3=A9?= de Strasbourg
Message-ID: <87zgj7xg89.fsf@universite-de-strasbourg.fr.invalid>
References: <t6dj6a$sg8$1@gioia.aioe.org> <t6djq7$1570$1@gioia.aioe.org>
	<87o7zod3s7.fsf@izac.org>
	<877d6czfdn.fsf@universite-de-strasbourg.fr.invalid>
	<87k0accue3.fsf@izac.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="19841"; posting-host="K7PIs9tCGQ+WHJa7e6BylQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:08H/hvuUGYMsn/UoDRdzkmxhUtQ=
Bytes: 1822
Lines: 21

Benoit Izac <use.reply.to@INVALID.ADDRESS> writes:

>>> def accumulate_sum_of(n):
>>>     return (n + 1) // 2 * (n + (n + 1) % 2)
>>
>> Hmm, pourquoi pas simplement n * (n+1) // 2 ?
>
> Parce que c'est toujours plus compliqu=C3=A9 de faire simple. ;-)

Cela =C3=A9tant, ta version est mieux adapt=C3=A9e aux contextes o=C3=B9 la=
 pr=C3=A9cision
est limit=C3=A9e, parce qu'elle =C3=A9vite les overflows quand n*(n+1) n'es=
t pas
repr=C3=A9sentable mais que n*(n+1)/2 l'est.

(=C3=87a ne concerne pas Python, mais c'est la m=C3=AAme id=C3=A9e qu'un bu=
g qui a =C3=A9t=C3=A9
c=C3=A9l=C3=A8bre en Java, dont la correction a consist=C3=A9 =C3=A0 rempla=
cer (a+b)/2 par
a + (b-a)/2.)

-- Alain.