Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #16077
| Path | csiph.com!aioe.org!W4+pUJJ+LMQSnRdpBvjvmw.user.46.165.242.91.POSTED!not-for-mail |
|---|---|
| From | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
| Newsgroups | comp.programming |
| Subject | Re: Another little puzzle |
| Date | Wed, 14 Dec 2022 14:35:19 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tncjem$19kh$1@gioia.aioe.org> (permalink) |
| References | <puzzle-20221214131815@ram.dialup.fu-berlin.de> <tncho3$ilr$1@gioia.aioe.org> <tnci0u$2of9h$3@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | gioia.aioe.org; logging-data="42641"; posting-host="W4+pUJJ+LMQSnRdpBvjvmw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 |
| X-Notice | Filtered by postfilter v. 0.9.2 |
| Content-Language | en-US |
| Xref | csiph.com comp.programming:16077 |
Show key headers only | View raw
On 2022-12-14 14:10, Richard Heathfield wrote:
> On 14/12/2022 1:06 pm, Dmitry A. Kazakov wrote:
>> On 2022-12-14 13:24, Stefan Ram wrote:
>>> Given n times of the 24-hour day, print their average.
>>>
>>> For example, the average of "eight o'clock" and
>>> "ten o'clock" (n=2) would be "nine o'clock".
>>
>> You probably missed to require the interesting part: doing all that in
>> the modular type (modulo 24) arithmetic:
>>
>> 20 + 5 = 1 (mod 24)
>
> ...which will give you the wrong answer. Chase that goose!
Right, you must count the wrap-ups. E.g.
for I in Times'Range loop
New_Sum := Old_Sum + Times (I);
if Old_Sum > New_Sum then -- Wrapped
Count := Count + 1;
if Count = n then -- Each n wrap-ups can be discarded
Count := 0;
end if;
end if;
Old_Sum := New_Sum;
end loop;
In the end you have to evaluate
(Old_Sum + Count * 24) / n (mod 24)
where Count < n is the wrap-ups count.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Another little puzzle "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-12-14 14:06 +0100
Re: Another little puzzle Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 13:10 +0000
Re: Another little puzzle "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-12-14 14:35 +0100
Re: Another little puzzle Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 14:10 +0000
Re: Another little puzzle "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-12-14 15:58 +0100
Re: Another little puzzle Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 15:18 +0000
Re: Another little puzzle "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-12-14 16:41 +0100
Re: Another little puzzle "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2022-12-14 16:43 +0100
Re: Another little puzzle Y A <angel00000100000@mail.ee> - 2023-01-09 16:33 -0800
Re: Another little puzzle Richard Heathfield <rjh@cpax.org.uk> - 2022-12-14 16:13 +0000
Re: Another little puzzle V <angleeeeeeee@mail.ee> - 2023-05-10 11:16 -0700
Re: Another little puzzle Ǝ <angel0000000001000000000000@mail.ee> - 2022-12-30 05:59 -0800
csiph-web