Cody

Problem 232. Project Euler: Problem 2, Sum of even Fibonacci

Solution 2900576

Submitted on 1 Sep 2020 by Jay Austin
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x =4000000 y_correct = 4613732; assert(isequal(euler002(x),y_correct))

x = 4000000 s = 1 2 3 s = 1 2 3 5 s = 1 2 3 5 8 s = 1 2 3 5 8 13 s = 1 2 3 5 8 13 21 s = 1 2 3 5 8 13 21 34 s = 1 2 3 5 8 13 21 34 55 s = 1 2 3 5 8 13 21 34 55 89 s = 1 2 3 5 8 13 21 34 55 89 144 s = 1 2 3 5 8 13 21 34 55 89 144 233 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 y = 4613732

2   Pass
x =97455000 y_correct = 82790070; assert(isequal(euler002(x),y_correct))

x = 97455000 s = 1 2 3 s = 1 2 3 5 s = 1 2 3 5 8 s = 1 2 3 5 8 13 s = 1 2 3 5 8 13 21 s = 1 2 3 5 8 13 21 34 s = 1 2 3 5 8 13 21 34 55 s = 1 2 3 5 8 13 21 34 55 89 s = 1 2 3 5 8 13 21 34 55 89 144 s = 1 2 3 5 8 13 21 34 55 89 144 233 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 34 2178309 3524578 5702887 9227465 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 35 2178309 3524578 5702887 9227465 14930352 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 36 2178309 3524578 5702887 9227465 14930352 24157817 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 37 2178309 3524578 5702887 9227465 14930352 24157817 39088169 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 38 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233...

3   Pass
x =597455000 y_correct = 350704366; assert(isequal(euler002(x),y_correct))

x = 597455000 s = 1 2 3 s = 1 2 3 5 s = 1 2 3 5 8 s = 1 2 3 5 8 13 s = 1 2 3 5 8 13 21 s = 1 2 3 5 8 13 21 34 s = 1 2 3 5 8 13 21 34 55 s = 1 2 3 5 8 13 21 34 55 89 s = 1 2 3 5 8 13 21 34 55 89 144 s = 1 2 3 5 8 13 21 34 55 89 144 233 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Column 31 2178309 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 32 2178309 3524578 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 33 2178309 3524578 5702887 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 34 2178309 3524578 5702887 9227465 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 35 2178309 3524578 5702887 9227465 14930352 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 36 2178309 3524578 5702887 9227465 14930352 24157817 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 37 2178309 3524578 5702887 9227465 14930352 24157817 39088169 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 30 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 Columns 31 through 38 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233...

4   Pass
x =666576 y_correct = 257114; assert(isequal(euler002(x),y_correct))

x = 666576 s = 1 2 3 s = 1 2 3 5 s = 1 2 3 5 8 s = 1 2 3 5 8 13 s = 1 2 3 5 8 13 21 s = 1 2 3 5 8 13 21 34 s = 1 2 3 5 8 13 21 34 55 s = 1 2 3 5 8 13 21 34 55 89 s = 1 2 3 5 8 13 21 34 55 89 144 s = 1 2 3 5 8 13 21 34 55 89 144 233 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 s = 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Column 16 1597 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 17 1597 2584 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 18 1597 2584 4181 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 19 1597 2584 4181 6765 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 20 1597 2584 4181 6765 10946 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 21 1597 2584 4181 6765 10946 17711 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 22 1597 2584 4181 6765 10946 17711 28657 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 23 1597 2584 4181 6765 10946 17711 28657 46368 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 24 1597 2584 4181 6765 10946 17711 28657 46368 75025 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 25 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 26 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 27 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 29 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 s = Columns 1 through 15 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Columns 16 through 28 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 y = 257114

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!