This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
"bufio" | |
"strings" | |
"strconv" | |
"os" |
This file contains hidden or 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 input(ans chan int) { | |
r := bufio.NewReader(os.Stdin) | |
for { | |
line, _, err := r.ReadLine() | |
if err != nil { | |
fmt.Print(">") | |
continue | |
} |
This file contains hidden or 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
ans := make(chan int) | |
go input(ans) | |
rnd := rand.New(rand.NewSource(time.Now().UnixNano())) | |
count := 0 | |
for i:= 1; i <= 10; i++ { | |
n := rnd.Intn(100) | |
m := rnd.Intn(100) | |
fmt.Printf("%2d : %2d + %2d = ", i, n, m) | |
select { |
This file contains hidden or 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 countdown(n uint) { | |
for i := 0; i < int(n); i++ { | |
fmt.Print(int(n)-i) | |
<-time.After(1 * time.Second) | |
fmt.Print(" ") | |
} | |
fmt.Println() | |
fmt.Println("Start!!") | |
} |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"bufio" | |
"os" | |
"strconv" | |
"strings" | |
"math/rand" | |
"time" |
This file contains hidden or 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
// バッファなし | |
ch := make(chan int) | |
// バッッファあり | |
chbuf := make(chan int, 100) |
This file contains hidden or 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
// 受信専用 | |
rch := make(<-chan int) | |
// 送信専用 | |
sch := make(chan<- int) |
This file contains hidden or 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
package main | |
func main() { | |
ch := make(<-chan int) | |
ch <- 100 | |
} |
This file contains hidden or 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
package main | |
func main() { | |
ch := make(chan<- int) | |
<-ch | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func main() { | |
// read and write | |
ch1 := make(chan int) | |
fmt.Printf("ch1=%t\n", ch1) |