1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "runtime"
13 "strconv"
14
15 "cgostdio/stdio"
16 )
17
18 const N = 10
19 const R = 5
20
21 func link(left chan<- int, right <-chan int) {
22
23
24
25 runtime.LockOSThread()
26 for {
27 v := <-right
28 stdio.Stdout.WriteString(strconv.Itoa(v) + "\n")
29 left <- 1 + v
30 }
31 }
32
33 func main() {
34 leftmost := make(chan int)
35 var left chan int
36 right := leftmost
37 for i := 0; i < N; i++ {
38 left, right = right, make(chan int)
39 go link(left, right)
40 }
41 for i := 0; i < R; i++ {
42 right <- 0
43 x := <-leftmost
44 stdio.Stdout.WriteString(strconv.Itoa(x) + "\n")
45 }
46 }
47
View as plain text