Skip to content

Instantly share code, notes, and snippets.

@xmonkee
Forked from anonymous/evenFib
Created January 26, 2014 02:17
Show Gist options
  • Save xmonkee/8627213 to your computer and use it in GitHub Desktop.
Save xmonkee/8627213 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func isEven(n int, c chan<- int) {
if n%2 == 0{
c <- n
}
}
func main() {
fib1 := 1
fib2 := 2
total := 0
c := make(chan int)
for fib1 <= 4000000 {
fib1, fib2 = fib2, fib1+fib2
go isEven(fib1,c)
}
for {
select {
case e := <-c:
total += e
default:
fmt.Println(total)
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment