Example #1
0
 bool isValidSudoku(vector<vector<char> > &board) {
     vector<char> candidates;
     for (size_t i = 0; i < 9; i++) {
         candidates = getIthRow(board, i);
         if (!isValidSequence(candidates)) {
             return false;
         }
     }
     for (size_t i = 0; i < 9; i++) {
         candidates = getIthColumn(board, i);
         if (!isValidSequence(candidates)) {
             return false;
         }
     }
     for (size_t i = 0; i < 9; i++) {
         candidates = getIthSquare(board, i);
         if (!isValidSequence(candidates)) {
             return false;
         }
     }
     return true;
 }
Example #2
0
    boost::shared_ptr<double> LCEBEvaluation::evaluate(Chromosome const & chr)const {
        int length = chr.numberOfGenes();
        boost::scoped_array<int> decimals(new int[length]);
        chr.convertGenesToDecimals(decimals.get());
        boost::shared_ptr<double> res;

        if (!isValidSequence(decimals.get()))
            return res;

        /*std::stack<double> operands;

        for(int i = 0; i < length; ++i){
            int index = decimals[i];
            int nDrawnBooklets = game.getNumberOfDrawnBooklets();

            if(index < nDrawnBooklets){
                operands.push((double)game.getDrawnBooklet(index));
            }
            else{
                if(index < nDrawnBooklets + OPERATORS.length){
                    double operand2;
                    double operand1;

                    try{
                        operand2 = operands.pop();
                    }
                    catch(EmptyStackException e){
                        return res;
                    }
                    
                    try{
                        operand1 = operands.pop();
                    }
                    catch(EmptyStackException e){
                        return res;
                    }

                    if(res == null){
                        res = 0.0;
                    }

                    switch(OPERATORS[(index-nDrawnBooklets)]){
                        case '*':
                            res = operand1 * operand2;
                            break;

                        case '/':
                            if( operand2 != 0.0f && operand1 != 0.0f &&
                                    operand1 % operand2 == 0){
                                res = operand1 / operand2;
                            }
                            else{
                                res = null;
                                return res;
                            }

                            break;

                        case '+':
                            res = operand1 + operand2;
                            break;

                        case '-':
                            res = operand1 - operand2;
                            break;

                        default:
                            break;
                    }

                    operands.push(res);
                }
            }
        }*/

        return res;
    }
Example #3
0
bool isValidSequence(const Cmds &commands,
                     const typename Cmds::value_type::element_type::Model &s0) {
  return isValidSequence(commands, fn::constant(s0));
}