Skip to content

Instantly share code, notes, and snippets.

@quux00
Created January 16, 2014 04:56
Show Gist options
  • Save quux00/8449996 to your computer and use it in GitHub Desktop.
Save quux00/8449996 to your computer and use it in GitHub Desktop.
Chinese Whispers example by Rob Pike http://www.youtube.com/watch?v=f6kdp27TYZs
package main
import "fmt"
//
// Chinese Whispers example by Rob Pike
// See http://www.youtube.com/watch?v=f6kdp27TYZs
//
func whisper(left, right chan int) {
left <- 1 + <- right
}
func main() {
const n = 100000
leftmost := make(chan int)
right := leftmost
left := leftmost
for i := 0; i < n; i++ {
right = make(chan int)
go whisper(left, right)
left = right
}
go func(c chan int) { c <- 1 }(right)
fmt.Println(<- leftmost)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment