Esempio n. 1
0
/*
 calculates the value for the result matrix for cell

 @param *m1    matrix 1 of multiplication
 @param *m2    matrix 2 of multiplication
 @param terms  number of terms in the multiplication
 @param rows   number of rows in the result matrix
 @param cols   number of columns in the result matrix
 @param cell   the cell in the result matrix we are calculating the value of

 @return    the value of cell in the result matrix
 */
int calc_cell(int *m1, int *m2, int terms, int rows, int cols, int cell) {
  int i, sum = 0;
  int row = cell2row(cols, cell);
  int col = cell2col(cols, cell);
  for (i=0; i<terms; i++)
    sum += m1[rowcol2cell(terms, row, i)] * m2[rowcol2cell(cols, i, col)];
  return sum;
}
Esempio n. 2
0
int set_dlx_h_sudoku(struct dlx_head *h, const struct sudoku_dsr *sudoku,
			struct dlx_node **save_node)
{
	int i, j;
	int val;
	int row;
	int n = 0;

	assert(h && sudoku);
	for (i = 0; i < sudoku->h; i++) {
		for (j = 0; j < sudoku->w; j++) {
			val = *(sudoku->data + i * sudoku->w + j);
			if (val > 0) {
				row = cell2row(i, j, val);
				*(save_node + n) = find_row_node(h, row);
				if (dlx_select_row(*(save_node + n)) < 0) {
					return -1;
				}
				n++;
			}
		}
	}
	return 0;
}