Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Even Fibonacci numbers Sum

Even Fibonacci numbers sum whose values do not exceed four million. I am using multiline function in APL, but not getting the output:

result←Euler2 a;b;c;sum;i;limit
 b←0
 c←1
 sum←0
 i←0
 limit←4000000
 :For i :In limit
     a←b
     b←c
     c←a+b
     :If (0=2|c)
         sum←(sum+c)
     :EndIf
 :EndFor
 result←sum

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Warning: opinions below.

I would avoid using manual loops and tradfns. The resulting solution will (often) be clunky and slow. APL has powerful abilities for array processing, use them as much as you can.

Here’s a different possible solution, using ‘dfns’.

+/{⍵/⍨0=2|⍵} {⍵,⍨+/2↑⍵}⍣{4000000<⊃⍺} 1 1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading