Skip to content

Commit fa9541c

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank]: Project Euler #2: Even Fibonacci numbers. Some logs added.
1 parent 5f13b1a commit fa9541c

File tree

1 file changed

+14
-5
lines changed
  • algorithm-exercises-csharp/src/hackerrank/projecteuler

1 file changed

+14
-5
lines changed

algorithm-exercises-csharp/src/hackerrank/projecteuler/Euler002.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,33 @@ protected Euler002() { }
1111

1212
public static int fiboEvenSum(int n)
1313
{
14-
int total = 0;
14+
Log.info("fiboEvenSum({n})", n);
15+
16+
int i = 0;
17+
int even_sum = 0;
1518
int fibo;
1619
int fibo1 = 1;
1720
int fibo2 = 1;
1821

1922
while (fibo1 + fibo2 < n)
2023
{
2124
fibo = fibo1 + fibo2;
22-
fibo1 = fibo2;
23-
fibo2 = fibo;
25+
26+
Log.info("Fibonacci({i}) = {fibo}", i, fibo);
2427

2528
if (fibo % 2 == 0)
2629
{
27-
total += fibo;
30+
even_sum += fibo;
2831
}
32+
33+
fibo1 = fibo2;
34+
fibo2 = fibo;
35+
i += 1;
2936
}
3037

31-
return total;
38+
Log.info("Problem 0002 result: {even_sum}", even_sum);
39+
40+
return even_sum;
3241
}
3342

3443
// Function to find the sum of all multiples of a and b below n

0 commit comments

Comments
 (0)