```zsh-users
help / color / mirror / code / Atom feed```
```From: "Lawrence Velázquez" <vq@larryv.me>
Cc: zsh-users@zsh.org
Subject: Re: run time of math problem
Date: Fri, 19 Mar 2021 23:59:37 -0400	[thread overview]
Message-ID: <5F4EC7FA-639D-42A9-BCB6-C0477F675509@larryv.me> (raw)

> On Mar 19, 2021, at 10:40 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> As to the rest I was just stupidly forgetting that I'm in a loop.
> I'm faking a summation. We don't have summation do we?

Not that I'm aware of, but you're computing partial sums of geometric
series [*], so you have a closed-form expression available to you:

for (( level = 1; level < 100; level++ )); do
((
remainder = (level - 1.0) / level,
sum = level - level * remainder**level,
divided = sum * (1.0 / level)
))
echo for level: \$level, survival: \$divided
done

[*]: https://mathworld.wolfram.com/GeometricSeries.html

--
vq

```

```     prev parent reply	other threads:[~2021-03-20  4:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 23:18 Ray Andrews
2021-03-19 23:46 ` Lawrence Velázquez
2021-03-19 23:51   ` Ray Andrews
2021-03-19 23:52 ` Oliver Kiddle
2021-03-20  2:40   ` Ray Andrews
2021-03-20  3:59     ` Lawrence Velázquez [this message]
```

```Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,

Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

switches of git-send-email(1):

git send-email \
--to=vq@larryv.me \
--cc=zsh-users@zsh.org \

https://kernel.org/pub/software/scm/git/docs/git-send-email.html

```Code repositories for project(s) associated with this public inbox