|
@@ -6,52 +6,52 @@ import (
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func (solver *Solver) populate_blocks() {
|
|
|
|
|
|
|
+func (solver *Solver) populateBlocks() {
|
|
|
|
|
|
|
|
defer solver.timeTrack(time.Now(), "Populated blocks")
|
|
defer solver.timeTrack(time.Now(), "Populated blocks")
|
|
|
log.Println("Populating blocks")
|
|
log.Println("Populating blocks")
|
|
|
|
|
|
|
|
- solver.find_blocks(&solver.row1, &solver.row1s)
|
|
|
|
|
- solver.find_blocks(&solver.row2, &solver.row2s)
|
|
|
|
|
- solver.find_blocks(&solver.row3, &solver.row3s)
|
|
|
|
|
- solver.find_blocks(&solver.row4, &solver.row4s)
|
|
|
|
|
- solver.find_blocks(&solver.row5, &solver.row5s)
|
|
|
|
|
- solver.find_blocks(&solver.row6, &solver.row6s)
|
|
|
|
|
- solver.find_blocks(&solver.row7, &solver.row7s)
|
|
|
|
|
- solver.find_blocks(&solver.row8, &solver.row8s)
|
|
|
|
|
- solver.find_blocks(&solver.row9, &solver.row9s)
|
|
|
|
|
|
|
+ solver.findBlocks(&solver.row1, &solver.row1s)
|
|
|
|
|
+ solver.findBlocks(&solver.row2, &solver.row2s)
|
|
|
|
|
+ solver.findBlocks(&solver.row3, &solver.row3s)
|
|
|
|
|
+ solver.findBlocks(&solver.row4, &solver.row4s)
|
|
|
|
|
+ solver.findBlocks(&solver.row5, &solver.row5s)
|
|
|
|
|
+ solver.findBlocks(&solver.row6, &solver.row6s)
|
|
|
|
|
+ solver.findBlocks(&solver.row7, &solver.row7s)
|
|
|
|
|
+ solver.findBlocks(&solver.row8, &solver.row8s)
|
|
|
|
|
+ solver.findBlocks(&solver.row9, &solver.row9s)
|
|
|
|
|
|
|
|
// This calculates and stores the total number of solutions to validate.
|
|
// This calculates and stores the total number of solutions to validate.
|
|
|
solver.iter = int64(len(solver.row1s)) * int64(len(solver.row2s)) * int64(len(solver.row3s)) * int64(len(solver.row4s)) * int64(len(solver.row5s)) * int64(len(solver.row6s)) * int64(len(solver.row7s)) * int64(len(solver.row8s)) * int64(len(solver.row9s))
|
|
solver.iter = int64(len(solver.row1s)) * int64(len(solver.row2s)) * int64(len(solver.row3s)) * int64(len(solver.row4s)) * int64(len(solver.row5s)) * int64(len(solver.row6s)) * int64(len(solver.row7s)) * int64(len(solver.row8s)) * int64(len(solver.row9s))
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (solver *Solver) find_blocks(row *string, rows *[]int) {
|
|
|
|
|
|
|
+func (solver *Solver) findBlocks(row *string, rows *[]int) {
|
|
|
// Declare selection
|
|
// Declare selection
|
|
|
var selection []int
|
|
var selection []int
|
|
|
- var curr_blocks []int
|
|
|
|
|
- func_row := *row
|
|
|
|
|
|
|
+ var currBlocks []int
|
|
|
|
|
+ funcRow := *row
|
|
|
|
|
|
|
|
- for letter := range func_row {
|
|
|
|
|
|
|
+ for letter := range funcRow {
|
|
|
|
|
|
|
|
if len(selection) == 0 {
|
|
if len(selection) == 0 {
|
|
|
- curr_blocks = solver.blocks
|
|
|
|
|
|
|
+ currBlocks = solver.blocks
|
|
|
} else {
|
|
} else {
|
|
|
- curr_blocks = selection
|
|
|
|
|
|
|
+ currBlocks = selection
|
|
|
selection = nil
|
|
selection = nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for _, block := range curr_blocks {
|
|
|
|
|
|
|
+ for _, block := range currBlocks {
|
|
|
|
|
|
|
|
- curr_row := strconv.Itoa(block)
|
|
|
|
|
|
|
+ currRow := strconv.Itoa(block)
|
|
|
|
|
|
|
|
- if func_row[letter] == curr_row[letter] {
|
|
|
|
|
- found_row, _ := strconv.Atoi(curr_row)
|
|
|
|
|
- selection = append(selection, found_row)
|
|
|
|
|
|
|
+ if funcRow[letter] == currRow[letter] {
|
|
|
|
|
+ foundRow, _ := strconv.Atoi(currRow)
|
|
|
|
|
+ selection = append(selection, foundRow)
|
|
|
}
|
|
}
|
|
|
- if func_row[letter] == '0' {
|
|
|
|
|
- found_row, _ := strconv.Atoi(curr_row)
|
|
|
|
|
- selection = append(selection, found_row)
|
|
|
|
|
|
|
+ if funcRow[letter] == '0' {
|
|
|
|
|
+ foundRow, _ := strconv.Atoi(currRow)
|
|
|
|
|
+ selection = append(selection, foundRow)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} // End for-loop
|
|
} // End for-loop
|
|
@@ -61,17 +61,17 @@ func (solver *Solver) find_blocks(row *string, rows *[]int) {
|
|
|
*rows = selection
|
|
*rows = selection
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (solver *Solver) check_combinations() {
|
|
|
|
|
- for rows1_index := range solver.row1s {
|
|
|
|
|
- for rows2_index := range solver.row2s {
|
|
|
|
|
- for rows3_index := range solver.row3s {
|
|
|
|
|
- for rows4_index := range solver.row4s {
|
|
|
|
|
- for rows5_index := range solver.row5s {
|
|
|
|
|
- for rows6_index := range solver.row6s {
|
|
|
|
|
- for rows7_index := range solver.row7s {
|
|
|
|
|
- for rows8_index := range solver.row8s {
|
|
|
|
|
- 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)
|
|
|
|
|
|
|
+func (solver *Solver) checkCombinations() {
|
|
|
|
|
+ for rows1Index := range solver.row1s {
|
|
|
|
|
+ for rows2Index := range solver.row2s {
|
|
|
|
|
+ for rows3Index := range solver.row3s {
|
|
|
|
|
+ for rows4Index := range solver.row4s {
|
|
|
|
|
+ for rows5Index := range solver.row5s {
|
|
|
|
|
+ for rows6Index := range solver.row6s {
|
|
|
|
|
+ for rows7Index := range solver.row7s {
|
|
|
|
|
+ for rows8Index := range solver.row8s {
|
|
|
|
|
+ for rows9Index := range solver.row9s {
|
|
|
|
|
+ go solver.routineValidator(rows1Index, rows2Index, rows3Index, rows4Index, rows5Index, rows6Index, rows7Index, rows8Index, rows9Index)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -83,13 +83,13 @@ func (solver *Solver) check_combinations() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (solver *Solver) routine_validator(rows1_index int, rows2_index int, rows3_index int, rows4_index int, rows5_index int, rows6_index int, rows7_index int, rows8_index int, rows9_index int) {
|
|
|
|
|
|
|
+func (solver *Solver) routineValidator(rows1Index int, rows2Index int, rows3Index int, rows4Index int, rows5Index int, rows6Index int, rows7Index int, rows8Index int, rows9Index int) {
|
|
|
|
|
|
|
|
// solver.counter = solver.counter + 1
|
|
// solver.counter = solver.counter + 1
|
|
|
solver.counter.Add(1)
|
|
solver.counter.Add(1)
|
|
|
|
|
|
|
|
- if solver.validate_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]) {
|
|
|
|
|
- solver.solutions = append(solver.solutions, solver.render_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]))
|
|
|
|
|
|
|
+ if solver.validateCombination(solver.row1s[rows1Index], solver.row2s[rows2Index], solver.row3s[rows3Index], solver.row4s[rows4Index], solver.row5s[rows5Index], solver.row6s[rows6Index], solver.row7s[rows7Index], solver.row8s[rows8Index], solver.row9s[rows9Index]) {
|
|
|
|
|
+ solver.solutions = append(solver.solutions, solver.renderCombination(solver.row1s[rows1Index], solver.row2s[rows2Index], solver.row3s[rows3Index], solver.row4s[rows4Index], solver.row5s[rows5Index], solver.row6s[rows6Index], solver.row7s[rows7Index], solver.row8s[rows8Index], solver.row9s[rows9Index]))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -108,13 +108,13 @@ func (solver *Solver) tracker() {
|
|
|
var track int
|
|
var track int
|
|
|
|
|
|
|
|
// Tracking the rate, starting point
|
|
// Tracking the rate, starting point
|
|
|
- var rate_start int64
|
|
|
|
|
|
|
+ var rateStart int64
|
|
|
// Tracking the rate, difference between previous iterations
|
|
// Tracking the rate, difference between previous iterations
|
|
|
- var rate_diff int64
|
|
|
|
|
|
|
+ var rateDiff int64
|
|
|
|
|
|
|
|
// Tracking duration
|
|
// Tracking duration
|
|
|
- var timer_start = time.Now()
|
|
|
|
|
- // Prevent division-by-zero error when establishing `rate_diff`
|
|
|
|
|
|
|
+ var timerStart = time.Now()
|
|
|
|
|
+ // Prevent division-by-zero error when establishing `rateDiff`
|
|
|
time.Sleep(time.Second)
|
|
time.Sleep(time.Second)
|
|
|
|
|
|
|
|
// Estimation how long it will take
|
|
// Estimation how long it will take
|
|
@@ -127,23 +127,23 @@ func (solver *Solver) tracker() {
|
|
|
percentage = (float32(solver.counter.Load()) / (float32(solver.iter) / 100))
|
|
percentage = (float32(solver.counter.Load()) / (float32(solver.iter) / 100))
|
|
|
|
|
|
|
|
// Reset the loop
|
|
// Reset the loop
|
|
|
- rate_diff = solver.counter.Load() - rate_start
|
|
|
|
|
|
|
+ rateDiff = solver.counter.Load() - rateStart
|
|
|
|
|
|
|
|
- if track <= int(percentage) || rate_diff == 0 { // Start if-statement
|
|
|
|
|
|
|
+ if track <= int(percentage) || rateDiff == 0 { // Start if-statement
|
|
|
|
|
|
|
|
- // Make sure something happened, making rate_start the only reliable variable
|
|
|
|
|
- if rate_diff == 0 {
|
|
|
|
|
|
|
+ // Make sure something happened, making rateStart the only reliable variable
|
|
|
|
|
+ if rateDiff == 0 {
|
|
|
percentage = 100
|
|
percentage = 100
|
|
|
solver.counter.Store(solver.iter)
|
|
solver.counter.Store(solver.iter)
|
|
|
done = true
|
|
done = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- timer_elapsed := time.Since(timer_start)
|
|
|
|
|
- solver.rates = append(solver.rates, rate_diff)
|
|
|
|
|
- rate_avg := solver.calc_avg()
|
|
|
|
|
|
|
+ timer_elapsed := time.Since(timerStart)
|
|
|
|
|
+ solver.rates = append(solver.rates, rateDiff)
|
|
|
|
|
+ rate_avg := solver.calcAVG()
|
|
|
|
|
|
|
|
// Estimate when this is finished
|
|
// Estimate when this is finished
|
|
|
- if rate_diff == 0 {
|
|
|
|
|
|
|
+ if rateDiff == 0 {
|
|
|
est_fin = "N/A"
|
|
est_fin = "N/A"
|
|
|
} else {
|
|
} else {
|
|
|
duration_int := (solver.iter - solver.counter.Load()) / rate_avg
|
|
duration_int := (solver.iter - solver.counter.Load()) / rate_avg
|
|
@@ -156,7 +156,7 @@ func (solver *Solver) tracker() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Printing the progress
|
|
// Printing the progress
|
|
|
- log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.FormatInt(solver.counter.Load(), 10) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.FormatInt(rate_diff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
|
|
|
|
|
|
|
+ log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.FormatInt(solver.counter.Load(), 10) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.FormatInt(rateDiff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin)
|
|
|
|
|
|
|
|
// After we are done printing, exit this for-loop
|
|
// After we are done printing, exit this for-loop
|
|
|
if percentage == 100 {
|
|
if percentage == 100 {
|
|
@@ -170,12 +170,12 @@ func (solver *Solver) tracker() {
|
|
|
track = track + 1
|
|
track = track + 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- timer_start = time.Now()
|
|
|
|
|
|
|
+ timerStart = time.Now()
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Resert the rate counter
|
|
// Resert the rate counter
|
|
|
- rate_start = solver.counter.Load()
|
|
|
|
|
|
|
+ rateStart = solver.counter.Load()
|
|
|
|
|
|
|
|
// Sleep for a second
|
|
// Sleep for a second
|
|
|
time.Sleep(1 * time.Second)
|
|
time.Sleep(1 * time.Second)
|
|
@@ -184,7 +184,7 @@ func (solver *Solver) tracker() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (solver *Solver) validate_combination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) (retval bool) {
|
|
|
|
|
|
|
+func (solver *Solver) validateCombination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) (retval bool) {
|
|
|
retval = true
|
|
retval = true
|
|
|
|
|
|
|
|
row1s := strconv.Itoa(row1)
|
|
row1s := strconv.Itoa(row1)
|
|
@@ -239,14 +239,14 @@ func (solver *Solver) validate_combination(row1 int, row2 int, row3 int, row4 in
|
|
|
return retval
|
|
return retval
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (solver *Solver) calc_avg() (avg int64) {
|
|
|
|
|
- var avg_sum int64
|
|
|
|
|
|
|
+func (solver *Solver) calcAVG() (avg int64) {
|
|
|
|
|
+ var avgSum int64
|
|
|
|
|
|
|
|
for _, value := range solver.rates {
|
|
for _, value := range solver.rates {
|
|
|
- avg_sum += value
|
|
|
|
|
|
|
+ avgSum += value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- avg = avg_sum / int64(len(solver.rates))
|
|
|
|
|
|
|
+ avg = avgSum / int64(len(solver.rates))
|
|
|
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|