-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Jeyabalaji Subramanian edited this page Jun 21, 2020
·
2 revisions
Welcome to the go-sudoku-solver wiki!
This solver is all about recursion and concurrency!
- We start with an unsolved puzzle.
- For each empty cell, we find out a set of eligible numbers
- Pick a cell with least eligible numbers to start the guesswork
- On this cell, create a go routine to call Solve (recursively) passing each eligible number
- The step 1 to 4 is repeated once again and so on and so forth
Here's a common pattern for spawning multiple go routines:
chanMyChannel := make(chan Channel)
wg := new(sync.WaitGroup)
// Spawn multiple threads
go func() {
defer wg.Done()
// do work & send the data in channel
}(wg, &chanMyChannel)
// wait for all threads to complete
go func(wg *sync.WaitGroup, c chan Channel) {
wg.Wait()
close(c)
}(wg, chanMyChannel)
// collect the results from channel
for r := range chanMyChannel{
// reduce data
}