Created
January 13, 2018 04:51
-
-
Save rburdet/e05427d0288170936f83239f5536b37c to your computer and use it in GitHub Desktop.
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" | |
| import "math/rand" | |
| import "time" | |
| const N int = 1000 | |
| func main() { | |
| valid := make(chan bool, N) | |
| a := create() | |
| for idx := range a { | |
| go processRow(a[idx], valid) | |
| } | |
| for idx := range a { | |
| if <-valid { | |
| fmt.Println(idx) | |
| } | |
| } | |
| } | |
| func processRow(row []int, valid chan bool) { | |
| time.Sleep(time.Second * 2) | |
| var acum int = 0 | |
| for i := range row { | |
| acum = acum + row[i] | |
| } | |
| valid <- acum > N/2 | |
| } | |
| func create() [][]int { | |
| rand.Seed(time.Now().UnixNano()) | |
| rows, columns := N, N | |
| matrix := make([][]int, rows) | |
| for i := 0; i < rows; i++ { | |
| matrix[i] = make([]int, columns) | |
| for j := 0; j < columns; j++ { | |
| matrix[i][j] = rand.Intn(2) | |
| } | |
| } | |
| return matrix | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment