Skip to content

Instantly share code, notes, and snippets.

@urakozz
Last active September 4, 2015 22:29
Show Gist options
  • Save urakozz/5d43e663ff39953b69b7 to your computer and use it in GitHub Desktop.
Save urakozz/5d43e663ff39953b69b7 to your computer and use it in GitHub Desktop.
Go notes
func main(){
wg := &sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
time.Sleep(time.Duration(rand.Intn(90)) * time.Millisecond)
msg := "echo" + strconv.Itoa(i)
fmt.Println(msg)
}(i)
}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
time.Sleep(50 * time.Millisecond)
msg := "echo() " + strconv.Itoa(i)
fmt.Println(msg)
}(i)
}
wg.Wait()
}
func main(){
ch := make(chan int)
wg := &sync.WaitGroup{}
for i := 100; i < 1000; i++ {
for j := 100; j < 1000; j++ {
num := i * j
go func(num int) {
if num <= t && num >100000 && isPalindrom(num) {
wg.Add(1)
ch <- num
}
}(num)
}
}
bst := BST{}
go func() {
for c := range ch {
fmt.Printf("c is %v\n", c)
bst.Insert(int64(c))
wg.Done()
}
}()
wg.Wait()
max, _ := bst.Max();
fmt.Printf("max is %v\n",max)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment