Skip to content

Instantly share code, notes, and snippets.

@merikan
Last active February 25, 2018 17:17
Show Gist options
  • Save merikan/ef2f86a8f308777bb0de to your computer and use it in GitHub Desktop.
Save merikan/ef2f86a8f308777bb0de to your computer and use it in GitHub Desktop.
Project Euler Solutions

This gist is for my project euler solutions

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 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