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 :
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