Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: run time of math problem
> On Mar 19, 2021, at 10:40 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author