Skip to content

Commit 87c03ec

Browse files
committed
doc: add notes
1 parent 884b789 commit 87c03ec

File tree

1 file changed

+23
-12
lines changed
  • algorithms-and-data-structures/project-euler/002-even-fibonacci-numbers

1 file changed

+23
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
# Project Euler 002 - Even Fibonacci Numbers
22

33
Each new term in the Fibonacci sequence is generated by adding the previous
4-
two terms. By starting with 0 and 1, the first 10 terms will be:
4+
two terms. Starting with 0 and 1, the first 10 terms are:
55

66
```text
77
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
88
```
99

1010
By considering the terms in the Fibonacci sequence whose values do not exceed
11-
`n`, find the sum of the even-valued terms.
11+
`limit`, find the sum of the even-valued terms.
1212

13-
The function signature is
13+
## Function Signature
1414

1515
```typescript
1616
function fiboEvenSum(limit: int): int
1717
```
1818

19+
## Expected Behavior
20+
21+
```
22+
In: -1
23+
Out: 0
24+
25+
In: 0
26+
Out: 0
27+
28+
In: 2
29+
Out: 2
30+
31+
In: 10
32+
Out: 10
33+
34+
In: 60
35+
Out: 44
36+
```
37+
1938
## Optimizations
2039
2140
Trial division isn't necessary. There are ways to only compute even fibonacci
2241
numbers, including:
2342
2443
- Every third number in the sequence is even
25-
- You can calculate only even members with `next fibo = 4 * next fibo + current fibo`
26-
27-
## Resources
28-
29-
- [Project Euler Problem 002][1]
30-
- [Project Euler Problem 002 at freeCodeCamp][2]
31-
32-
[1]: https://projecteuler.net/problem=2
33-
[2]: https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers
44+
- Calculating even values only with `next fibo = 4 * next fibo + current fibo`

0 commit comments

Comments
 (0)