Last active
March 5, 2019 10:28
-
-
Save LordRahl90/5d1237ffaad676bc7847116cf5be96a3 to your computer and use it in GitHub Desktop.
Even Fibonacci Implementation Project Euler #2
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
func chanFib(n int, f chan int) { | |
fmt.Println("N is: ", n) | |
defer close(f) | |
i, j := 0, 1 | |
for { | |
temp := i + j | |
f <- i + j | |
j, i = i+j, j | |
if temp >= n { | |
break | |
} | |
} | |
} | |
func main() { | |
f := make(chan int) | |
n := 4000000 | |
sum := 0 | |
go chanFib(n, f) | |
for val := range f { | |
if val%2 == 0 { | |
sum += val | |
} | |
} | |
fmt.Println("Sum is: ", sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment