2013-04-11 01:07:29 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2016-12-05 22:15:40 +01:00
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
2013-04-11 01:07:29 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2016-12-05 22:15:40 +01:00
|
|
|
lines := make(chan string)
|
|
|
|
|
count := make(chan int)
|
|
|
|
|
go func() {
|
|
|
|
|
c := 0
|
|
|
|
|
for l := range lines {
|
|
|
|
|
fmt.Println(l)
|
|
|
|
|
c++
|
|
|
|
|
}
|
|
|
|
|
count <- c
|
|
|
|
|
}()
|
2013-04-11 01:07:29 -07:00
|
|
|
|
2016-12-05 22:15:40 +01:00
|
|
|
f, err := os.Open("input.txt")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for s := bufio.NewScanner(f); s.Scan(); {
|
|
|
|
|
lines <- s.Text()
|
|
|
|
|
}
|
|
|
|
|
f.Close()
|
|
|
|
|
close(lines)
|
|
|
|
|
fmt.Println("Number of lines:", <-count)
|
2013-04-11 01:07:29 -07:00
|
|
|
}
|