问题描述
我想这个数独解算器 HTTP:// WWW。 emanueleferonato.com/2008/12/09/sudoku-creatorsolver-with-php/ 。它工作正常。
I tried this sudoku solver http://www.emanueleferonato.com/2008/12/09/sudoku-creatorsolver-with-php/. It works fine.
另见这个S preadsheet看到计算的更多详细信息:<一href="https://docs.google.com/s$p$padsheets/d/1OBJ1TbwlDI9uqHWJFqRlhrm3_9mNYGxwIGA1995ZX-A/edit?usp=sharing"相对=nofollow>取值preadsheet
Also see this spreadsheet to see more detail in calculation : spreadsheet
我明白是怎么ROW和COL扫描。从主板,我们知道:
I understand how the row and col scanning. From the board, we know that:
- 指数= 9 *行+ COL
- 行=地板(索引/ 9)
- 在山坳=索引%9
和为块,因为它从3×3板建立这样的公式: block_index = 3 * row_block + col_row
。由于每块有3行列数,所以公式 row_block =地板(行/ 3)
和 col_block =地板(COL / 3)
。从这里我们可以得出这样的结论:
And for the block, because it build from 3x3 board so the formula: block_index = 3*row_block + col_row
. Because per block there are 3 rows and cols, so the formula for row_block = floor(row/3)
and col_block = floor(col/3)
. From here we can conclude that:
block_index = 3*row_block + col_row
block_index = 3(floor(row/3)) + floor(col/3)
block_index = floor(row/3)*3 + floor(col/3)
这可以为这些功能说明:
This could explain for these function :
- return_row
- retun_col
- return_block
- is_possible_row
- is_possible_col
但我无法理解关于 is_possible_block
功能。下面是函数:
But I cannot understand about is_possible_block
function. Here is the function:
function is_possible_block($number,$block,$sudoku){
$possible = true;
for($x = 0;$x <= 8;$x++){
if($sudoku[floor($block / 3) * 27 + $x % 3 + 9 * floor($x / 3) + 3 * ($block % 3)] == $number){
$possible = false;
}
}
return $possible;
}
我知道什么 is_possible_block
功能:
floor($block / 3) * 27 + $x % 3 + 9 * floor($x / 3) + 3 * ($block % 3)
= 9row+col
= 9(floor($block/3)*3 + floor($x/3)) + ($x%3 + 3*($block%3))
row = 3row_block+row_x_block
floor($block/3) = row_block
floor($x/3) = row_x_block
col = 3col_block+col_x_block
如何 COL = 3col_block + col_x_block
,因为我所知道的,公式应该是这样的: COL = 3row_block + COL
。
How col = 3col_block+col_x_block
, because what I know, the formula should be like this : col = 3row_block+col
.
我知道 col_x_block
的意思是在0-8块列位置。而 row_block
意味着对行的位置0-2块。
I know col_x_block
mean column position on 0-8 block. And row_block
mean row position on 0-2 block.
你怎么解释这个公式?谢谢
How do you explain this formula? Thanks
更新
现在我知道了。 地板($块/ 3)* 3
和 3 *($段%3)
确定块左上角。然后地板($ X / 3)
和 $ X%3
移动块中的每一个细胞。
Now I know. floor($block/3)*3
and 3*($block%3)
determine top left corner in block. Then floor($x / 3)
and $x % 3
moves each cell in the block.
推荐答案
我在C ++中使用
for(int k = ((x - 1) / 3) * 3 + 1; k < ((x - 1) / 3) * 3 + 4; k++
由于X是整数/操作返回int值。
because of "x" is integer "/" operation return int value.
也许3(楼($块1/3))可以帮助你。
maybe 3(floor($block-1/3)) can help you.
这篇关于在数独解算器解释块扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!