digitalmars.D.learn - Range handling difficulties
- Menjanahary R. R. (18/18) Apr 24 I tried to solve Project Euler [problem
- H. S. Teoh (5/30) Apr 24 evenfib.until!(n => n > 4_000_000).sum.writeln;
- Menjanahary R. R. (2/7) Apr 24 Thanks a lot! You've made my day 😀
I tried to solve Project Euler [problem https://projecteuler.net/problem=2) using [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). Assuming `genEvenFibonacci` is the appropriate funtion in Explicit form, I got what I need like so: ``` auto evenfib = recurrence!genEvenFibonacci(2uL, 8uL); writeln; evenfib.take(11).sum.writeln; ``` But that's like cheating because there is no prior knowledge of `11`. I just got it manually by peeking at the sequence `[2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352]`. `14930352` must be filtered out because beyond the limit set! How to fix that properly using all the standard library capabilities programatically? I'm thinking of Range and/or std.algorithm.
Apr 24
On Wed, Apr 24, 2024 at 08:08:06AM +0000, Menjanahary R. R. via Digitalmars-d-learn wrote:I tried to solve Project Euler [problem https://projecteuler.net/problem=2) using [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). Assuming `genEvenFibonacci` is the appropriate funtion in Explicit form, I got what I need like so: ``` auto evenfib = recurrence!genEvenFibonacci(2uL, 8uL); writeln; evenfib.take(11).sum.writeln; ``` But that's like cheating because there is no prior knowledge of `11`. I just got it manually by peeking at the sequence `[2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352]`. `14930352` must be filtered out because beyond the limit set! How to fix that properly using all the standard library capabilities programatically? I'm thinking of Range and/or std.algorithm.evenfib.until!(n => n > 4_000_000).sum.writeln; T -- The trouble with TCP jokes is that it's like hearing the same joke over and over.
Apr 24
On Wednesday, 24 April 2024 at 14:22:10 UTC, H. S. Teoh wrote:On Wed, Apr 24, 2024 at 08:08:06AM +0000, Menjanahary R. R. via Digitalmars-d-learn wrote:Thanks a lot! You've made my day 😀[...]evenfib.until!(n => n > 4_000_000).sum.writeln; T
Apr 24