Beispiel #1
0
void block_groups(Sudoku &sudoku, int group_size, int row_block, int col_block)
{
    HammingWeightIterator subset_iter(group_size);
    int digit_subset;

    // for each set of n numbers S = {k1, k2, ... kn}:
    while ((digit_subset = subset_iter.next()) != -1)
    {
        // C(k) == set of columns containing k
        // C(S) == union of C(k) over k in S
        int blocks_containing = blockcells_containing_any(sudoku, row_block, col_block, digit_subset);

        // if size(C(S)) == n
        if (num_ones(blocks_containing) == group_size)
        {
            // remove all other possibilities from columns in C(S)
            SetBitIndexIterator block_iter(blocks_containing);
            auto end = SetBitIndexIterator::end();

            for (; block_iter != end; ++block_iter)
            {
                int row, col;
                blockunmask(mask(*block_iter), row, col);
                row += row_block * 3;
                col += col_block * 3;
                int prev = sudoku(row, col);
                sudoku.set(row, col, prev & digit_subset);
            }
        }
    }
}
Beispiel #2
0
/* applies a client provided apply function to each element in the array2b 
 * in a block-major fashion.
 */
void UArray2b_map(T array2b, void apply(int i, int j, T array2b,
                                        void *elem, void *cl), void *cl)
{
        assert(array2b);
        int row, col;
        int w = array2b->width;
        int h = array2b->height;
        int bs = array2b->blocksize;
        for (row = 0; row < block_dim(h, bs); row++){
                for(col = 0; col < block_dim(w, bs); col++){
                        /* now iterate through each block */
                        block_iter(array2b, col, row, apply, cl);
                }
        }
}