Exemple #1
0
// -------------------------------------------------------------------
// fromArray
// -------------------------------------------------------------------
boost::shared_ptr<Vec3D> Vec3D::fromArray(long int tp, boost::shared_ptr<void> array)
{
	if (tp == SFSDATATYPE_INT_ARRAY)
	{
		return fromIntArray((boost::static_pointer_cast<vector<long int> >)(array));
	}
	else if (tp == SFSDATATYPE_FLOAT_ARRAY)
	{
		return fromFloatArray((boost::static_pointer_cast<vector<float> >)(array));
	}
	else
		boost::throw_exception(boost::enable_error_info (std::runtime_error("Invalid Array Type, cannot convert to Vec3D!"))); 
}
int main(int argc, char* argv[]) {
    if(argc>1) {
        std::cout << generateSDMLine(solve(parseSDMLine(argv[1]))) << '\n';
        return 0;
    }

    int samplePuzzle1[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]=
    {   {1, 6, 0, 4, 0, 3, 0, 0, 9},
        {0, 4, 0, 9, 0, 0, 0, 8, 0},
        {0, 0, 0, 0, 0, 0, 0, 4, 0},
        {5, 0, 0, 0, 2, 0, 0, 0, 6},
        {0, 0, 7, 1, 0, 5, 2, 0, 0},
        {3, 0, 0, 0, 9, 0, 0, 0, 4},
        {0, 2, 0, 0, 0, 0, 0, 0, 0},
        {0, 3, 0, 0, 0, 4, 0, 5, 0},
        {7, 0, 0, 8, 0, 6, 0, 1, 2}
    };
    // Puzzle 277
    int samplePuzzle2[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]=
    {   {0, 4, 0, 0, 0, 0, 0, 0, 3},
        {1, 5, 0, 4, 0, 2, 0, 0, 0},
        {0, 0, 8, 0, 0, 3, 0, 0, 7},
        {0, 8, 0, 3, 4, 0, 0, 0, 2},
        {0, 7, 0, 0, 0, 0, 0, 4, 0},
        {4, 0, 0, 0, 5, 9, 0, 8, 0},
        {8, 0, 0, 2, 0, 0, 6, 0, 0},
        {0, 0, 0, 6, 0, 7, 0, 9, 1},
        {9, 0, 0, 0, 0, 0, 0, 2, 0}
    };

    // Puzzle 389
    int samplePuzzle3[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]=
    {   {0, 6, 0, 3, 0, 2, 0, 1, 0},
        {0, 4, 0, 0, 0, 0, 0, 7, 0},
        {8, 0, 1, 0, 0, 0, 2, 0, 9},
        {0, 0, 0, 4, 0, 1, 0, 0, 0},
        {3, 5, 0, 0, 0, 0, 0, 9, 1},
        {0, 0, 0, 8, 0, 3, 0, 0, 0},
        {2, 0, 3, 0, 0, 0, 9, 0, 7},
        {0, 1, 0, 0, 0, 0, 0, 3, 0},
        {0, 7, 0, 6, 0, 8, 0, 5, 0}
    };

    // Puzzle 441
    int samplePuzzle4[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]=
    {   {0, 0, 7, 4, 5, 0, 2, 0, 0},
        {0, 0, 9, 0, 0, 0, 0, 0, 1},
        {2, 0, 0, 9, 0, 0, 3, 4, 0},
        {0, 9, 6, 0, 8, 2, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 1, 9, 0, 8, 6, 0},
        {0, 8, 1, 0, 0, 7, 0, 0, 3},
        {3, 0, 0, 0, 0, 0, 5, 0, 0},
        {0, 0, 2, 0, 3, 4, 1, 0, 0}
    };

    // Puzzle 573
    int samplePuzzle5[SUDOKU_GRID_SIZE][SUDOKU_GRID_SIZE]=
    {   {0, 8, 0, 0, 0, 1, 6, 0, 0},
        {0, 0, 5, 0, 0, 0, 0, 0, 3},
        {3, 0, 0, 0, 0, 0, 0, 9, 0},
        {8, 5, 0, 9, 1, 0, 0, 0, 7},
        {0, 0, 9, 2, 0, 5, 3, 0, 0},
        {1, 0, 0, 0, 7, 4, 0, 5, 2},
        {0, 3, 0, 0, 0, 0, 0, 0, 6},
        {9, 0, 0, 0, 0, 0, 2, 0, 0},
        {0, 0, 8, 6, 0, 0, 0, 1, 0}
    };

    partialSolution sol = fromIntArray(samplePuzzle1);
    sol = solve(sol);
    display(sol);

    sol = fromIntArray(samplePuzzle2);
    sol = solve(sol);
    display(sol);

    sol = fromIntArray(samplePuzzle3);
    sol = solve(sol);
    display(sol);

    sol = fromIntArray(samplePuzzle4);
    sol = solve(sol);
    display(sol);

    sol = fromIntArray(samplePuzzle5);
    sol = solve(sol);
    display(sol);

    return 0;
}