int main(int argc, char *argv[]) { (void)argc; (void)argv; UArray2_T test_array; bool OK = true; test_array = UArray2_new(DIM1, DIM2, ELEMENT_SIZE); //These functions check that the dimension has been set correctly OK &= (UArray2_width(test_array) == DIM1); OK &= (UArray2_height(test_array) == DIM2); OK &= (UArray2_size(test_array) == ELEMENT_SIZE); /* Note: we are only setting a value on the corner of the array */ *((number *)UArray2_at(test_array, DIM1-1, DIM2-1)) = MARKER; printf("Trying column major\n"); UArray2_map_col_major(test_array, check_and_print, &OK); printf("Trying row major\n"); UArray2_map_row_major(test_array, check_and_print, &OK); printf(" width = %d\n", UArray2_width(test_array)); printf("height %d\n", UArray2_height(test_array)); UArray2_free(&test_array); printf("The array is %sOK!\n", (OK ? "" : "NOT ")); }
/* checks that each row, column, and 3x3 box has digits 1 through 9*/ void correct_sudoku(UArray2_T uarray2) { Bit_T bit = Bit_new(10); UArray2_map_row_major(uarray2, check_setof9, bit);; UArray2_map_col_major(uarray2, check_setof9, bit); UArray2_map_3x3_box(uarray2, check_setof9, bit); Bit_free(&bit); }
/* check_solution() * * Function coordinates the solution checking process by calling helper * functions that check each portion of the puzzle. Creates a new 9x1 array that * contains ones and zeros. If a 1 is stored in element i of the array, this * indicates that the number i+1 has already been seen in that portion of the * puzzle - and thus the solution is incorrect. The function also frees this * array at the end of the checking process to avoid memory leaks. */ void check_solution(UArray2_T array) { UArray2_T curr_line_arr = UArray2_new(9, 1, sizeof(int)); UArray2_map_row_major(array, row_check, &curr_line_arr); UArray2_map_col_major(array, col_check, &curr_line_arr); for (int i = 0; i < 9; i += 3) { for (int j = 0; j < 9; j += 3) { box_check(array, j, i, curr_line_arr); } } UArray2_free(&curr_line_arr); }