Skip to content

Instantly share code, notes, and snippets.

@LordRahl90
Last active March 5, 2019 10:28
Show Gist options
  • Save LordRahl90/5d1237ffaad676bc7847116cf5be96a3 to your computer and use it in GitHub Desktop.
Save LordRahl90/5d1237ffaad676bc7847116cf5be96a3 to your computer and use it in GitHub Desktop.
Even Fibonacci Implementation Project Euler #2
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