From 7aebaea67658710b1a949c05a9bc9c7bae395df5 Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Sun, 8 Dec 2024 01:28:32 +0100 Subject: [PATCH] Working. 1 hour for this set. --- solver/processing.go | 30 +++--------------------------- solver/solver.go | 2 -- solver/types.go | 3 --- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/solver/processing.go b/solver/processing.go index 36bdb47..51ba21a 100644 --- a/solver/processing.go +++ b/solver/processing.go @@ -57,13 +57,9 @@ func (solver *Solver) check_combinations() { for rows6_index := range solver.row6s { for rows7_index := range solver.row7s { for rows8_index := range solver.row8s { - defer solver.wg.Done() - solver.wg.Add(1) - go solver.routine_row8(rows1_index, rows2_index, rows3_index, rows4_index, rows5_index, rows6_index, rows7_index, rows8_index) - // for rows9_index := range solver.row9s { - // go solver.routine_validator(rows1_index, rows2_index, rows3_index, rows4_index, rows5_index, rows6_index, rows7_index, rows8_index, rows9_index) - // // } - // } + for rows9_index := range solver.row9s { + go solver.routine_validator(rows1_index, rows2_index, rows3_index, rows4_index, rows5_index, rows6_index, rows7_index, rows8_index, rows9_index) + } } } } @@ -75,72 +71,54 @@ func (solver *Solver) check_combinations() { } func (solver *Solver) routine_row1(index1 int) { - defer solver.wg.Done() for index2 := range solver.row2s { - solver.wg.Add(1) go solver.routine_row2(index1, index2) } } func (solver *Solver) routine_row2(index1 int, index2 int) { - defer solver.wg.Done() for index3 := range solver.row3s { - solver.wg.Add(1) go solver.routine_row3(index1, index2, index3) } } func (solver *Solver) routine_row3(index1 int, index2 int, index3 int) { - defer solver.wg.Done() for index4 := range solver.row4s { - solver.wg.Add(1) go solver.routine_row4(index1, index2, index3, index4) } } func (solver *Solver) routine_row4(index1 int, index2 int, index3 int, index4 int) { - defer solver.wg.Done() for index5 := range solver.row5s { - solver.wg.Add(1) go solver.routine_row5(index1, index2, index3, index4, index5) } } func (solver *Solver) routine_row5(index1 int, index2 int, index3 int, index4 int, index5 int) { - defer solver.wg.Done() for index6 := range solver.row6s { - solver.wg.Add(1) go solver.routine_row6(index1, index2, index3, index4, index5, index6) } } func (solver *Solver) routine_row6(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int) { - defer solver.wg.Done() for index7 := range solver.row7s { - solver.wg.Add(1) go solver.routine_row7(index1, index2, index3, index4, index5, index6, index7) } } func (solver *Solver) routine_row7(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int) { - defer solver.wg.Done() for index8 := range solver.row8s { - solver.wg.Add(1) go solver.routine_row8(index1, index2, index3, index4, index5, index6, index7, index8) } } func (solver *Solver) routine_row8(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int, index8 int) { - defer solver.wg.Done() for index9 := range solver.row9s { - solver.wg.Add(1) go solver.routine_row9(index1, index2, index3, index4, index5, index6, index7, index8, index9) } } func (solver *Solver) routine_row9(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int, index8 int, index9 int) { - defer solver.wg.Done() - solver.wg.Add(1) go solver.routine_validator(index1, index2, index3, index4, index5, index6, index7, index8, index9) } @@ -159,8 +137,6 @@ func (solver *Solver) routine_validator(rows1_index int, rows2_index int, rows3_ fmt.Println("Processing:", percentage, "%; Procs:", runtime.NumGoroutine()) } - solver.wg.Done() - } func (solver *Solver) validate_combination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) bool { diff --git a/solver/solver.go b/solver/solver.go index c10d8c5..5b4b8f0 100644 --- a/solver/solver.go +++ b/solver/solver.go @@ -2,7 +2,6 @@ package solver import ( "fmt" - "sync" ) func Run() { @@ -16,7 +15,6 @@ func Run() { solver.row7 = "597410280" solver.row8 = "006283090" solver.row9 = "200590006" - solver.wg = sync.WaitGroup{} solver.load_blocks() fmt.Println("Total blocks:", len(solver.blocks)) diff --git a/solver/types.go b/solver/types.go index 4a816e3..c0431a3 100644 --- a/solver/types.go +++ b/solver/types.go @@ -1,7 +1,5 @@ package solver -import "sync" - type Solver struct { blocks []int row1 string @@ -25,5 +23,4 @@ type Solver struct { iter int counter int solutions []string - wg sync.WaitGroup }