Esempio n. 1
0
func main() {
	target := 10001
	ch := make(chan int)
	go e.GenPrime(ch)
	for i := 0; i < int(target)-1; i++ {
		<-ch
		//fmt.Println(prime)
	}
	fmt.Println(<-ch)
}
Esempio n. 2
0
func main() {
	const max = 20000

	//fmt.Println(e.SumPrimes(max))

	sum := 0
	ch := make(chan int)
	go e.GenPrime(ch)
	for {
		p := <-ch
		if p < max {
			sum += p
			//fmt.Printf("Adding %v, sum so far: %v\n", p, sum)
		} else {
			fmt.Println(sum)
			return
		}
	}

}
Esempio n. 3
0
func main() {
	if !(len(os.Args) > 1) {
		fmt.Println("No argument found.")
		os.Exit(1)
	} else {
		//fmt.Println(os.Args[1])
		target, err := strconv.ParseInt(os.Args[1], 10, 32)
		if err != nil {
			fmt.Println("Please enter int as argument")
			os.Exit(1)
		}
		ch := make(chan int)
		go e.GenPrime(ch)
		for i := 0; i < int(target)-1; i++ {
			<-ch
			//fmt.Println(prime)
		}
		fmt.Println(<-ch)
	}
}