This gist is for my project euler solutions
Last active
February 25, 2018 17:17
-
-
Save merikan/ef2f86a8f308777bb0de to your computer and use it in GitHub Desktop.
Project Euler Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
var sum int | |
for i := 0; i < 1000000; i++ { | |
value := fib(i) | |
if value > 4000000 { | |
break | |
} | |
fmt.Print(value, ",") | |
if value % 2 == 0 { | |
sum += value | |
} | |
} | |
fmt.Println("\nThe sum of even values is: ", sum) | |
} | |
func fib(n int) int { | |
if n <= 1 { | |
return n | |
} else { | |
return fib(n - 1) + fib(n - 2) | |
} | |
} | |
/* | |
Each new term in the Fibonacci sequence is generated by adding the previous two terms. | |
By starting with 1 and 2, the first 10 terms will be: | |
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | |
By considering the terms in the Fibonacci sequence whose values do not exceed four | |
million, find the sum of the even-valued terms. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist is for my project euler solutions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment