File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
algorithm-exercises-csharp/src/hackerrank/projecteuler Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -11,24 +11,33 @@ protected Euler002() { }
11
11
12
12
public static int fiboEvenSum ( int n )
13
13
{
14
- int total = 0 ;
14
+ Log . info ( "fiboEvenSum({n})" , n ) ;
15
+
16
+ int i = 0 ;
17
+ int even_sum = 0 ;
15
18
int fibo ;
16
19
int fibo1 = 1 ;
17
20
int fibo2 = 1 ;
18
21
19
22
while ( fibo1 + fibo2 < n )
20
23
{
21
24
fibo = fibo1 + fibo2 ;
22
- fibo1 = fibo2 ;
23
- fibo2 = fibo ;
25
+
26
+ Log . info ( "Fibonacci({i}) = { fibo}" , i , fibo ) ;
24
27
25
28
if ( fibo % 2 == 0 )
26
29
{
27
- total += fibo ;
30
+ even_sum += fibo ;
28
31
}
32
+
33
+ fibo1 = fibo2 ;
34
+ fibo2 = fibo ;
35
+ i += 1 ;
29
36
}
30
37
31
- return total ;
38
+ Log . info ( "Problem 0002 result: {even_sum}" , even_sum ) ;
39
+
40
+ return even_sum ;
32
41
}
33
42
34
43
// Function to find the sum of all multiples of a and b below n
You can’t perform that action at this time.
0 commit comments