src/sudoku.c
L_SUDOKU *
sudokuCreate(l_int32  *array)
{
l_int32    i, val, locs_index;
L_SUDOKU  *sud;

    PROCNAME("sudokuCreate");

    if (!array)
        return (L_SUDOKU *)ERROR_PTR("array not defined", procName, NULL);

    locs_index = 0;  /* into locs array */
    if ((sud = (L_SUDOKU *)CALLOC(1, sizeof(L_SUDOKU))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("sud not made", procName, NULL);
    if ((sud->locs = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su state array not made", procName, NULL);
    if ((sud->init = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su init array not made", procName, NULL);
    if ((sud->state = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su state array not made", procName, NULL);
    for (i = 0; i < 81; i++) {
        val = array[i];
        sud->init[i] = val;
        sud->state[i] = val;
        if (val == 0)
            sud->locs[locs_index++] = i;
    }
    sud->num = locs_index;
    sud->failure = FALSE;
    sud->finished = FALSE;
    return sud;
}
/*!
 *  sudokuCreate()
 *
 *      Input:  array (of 81 numbers, 9 rows of 9 numbers each)
 *      Return: l_sudoku, or null on error
 *
 *  Notes:
 *      (1) The input array has 0 for the unknown values, and 1-9
 *          for the known initial values.  It is generated from
 *          a file using sudokuReadInput(), which checks that the file
 *          data has 81 numbers in 9 rows.
 */
sudokuCreate()
Input:  array (of 81 numbers, 9 rows of 9 numbers each)
Return: l_sudoku, or null on error

(1) The input array has 0 for the unknown values, and 1-9
for the known initial values.  It is generated from
a file using sudokuReadInput(), which checks that the file
data has 81 numbers in 9 rows.
sudokuCreate () Input : array ( of 81 numbers 9 rows of 9 numbers each ) Return : l_sudoku or null on error ( 1 ) The input array has 0 for the unknown values and 1 - 9 for the known initial values . It is generated from a file using sudokuReadInput () which checks that the file data has 81 numbers in 9 rows .
L_SUDOKU *
sudokuCreate(l_int32  *array)
{
l_int32    i, val, locs_index;
L_SUDOKU  *sud;
    PROCNAME("sudokuCreate");
    if (!array)
        return (L_SUDOKU *)ERROR_PTR("array not defined", procName, NULL);
    locs_index = 0;  
    if ((sud = (L_SUDOKU *)CALLOC(1, sizeof(L_SUDOKU))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("sud not made", procName, NULL);
    if ((sud->locs = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su state array not made", procName, NULL);
    if ((sud->init = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su init array not made", procName, NULL);
    if ((sud->state = (l_int32 *)CALLOC(81, sizeof(l_int32))) == NULL)
        return (L_SUDOKU *)ERROR_PTR("su state array not made", procName, NULL);
    for (i = 0; i < 81; i++) {
        val = array[i];
        sud->init[i] = val;
        sud->state[i] = val;
        if (val == 0)
            sud->locs[locs_index++] = i;
    }
    sud->num = locs_index;
    sud->failure = FALSE;
    sud->finished = FALSE;
    return sud;
}
L_SUDOKU * sudokuCreate ( l_int32 * array ) { l_int32 i , val , locs_index ; L_SUDOKU * sud ; PROCNAME ( " " ) ; if ( ! array ) return ( L_SUDOKU * ) ERROR_PTR ( " " , procName , NULL ) ; locs_index = 0 ; if ( ( sud = ( L_SUDOKU * ) CALLOC ( 1 , sizeof ( L_SUDOKU ) ) ) == NULL ) return ( L_SUDOKU * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ( sud -> locs = ( l_int32 * ) CALLOC ( 81 , sizeof ( l_int32 ) ) ) == NULL ) return ( L_SUDOKU * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ( sud -> init = ( l_int32 * ) CALLOC ( 81 , sizeof ( l_int32 ) ) ) == NULL ) return ( L_SUDOKU * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ( sud -> state = ( l_int32 * ) CALLOC ( 81 , sizeof ( l_int32 ) ) ) == NULL ) return ( L_SUDOKU * ) ERROR_PTR ( " " , procName , NULL ) ; for ( i = 0 ; i < 81 ; i ++ ) { val = array [ i ] ; sud -> init [ i ] = val ; sud -> state [ i ] = val ; if ( val == 0 ) sud -> locs [ locs_index ++ ] = i ; } sud -> num = locs_index ; sud -> failure = FALSE ; sud -> finished = FALSE ; return sud ; }
sudokuCreate()
      Input:  array (of 81 numbers, 9 rows of 9 numbers each)
      Return: l_sudoku, or null on error
sudokuCreate () Input : array ( of 81 numbers 9 rows of 9 numbers each ) Return : l_sudoku or null on error
/* into locs array */