<commit_before>// Dependencies
var sets = require('simplesets');

var sudokuSolver = {};

// Some public functions that will help the solver
// Run specs for this functions using jasmine
//
// Check if i is on the same row with j
global.sameRow = function(i, j) {
    return (Math.floor(i/9) == Math.floor(j/9));
}

// Check if i is on the same column with j
global.sameColumn = function(i, j) {
    return ((i - j) % 9 == 0);
}

// Check if i is in the same block with j
global.sameBlock = function(i, j) {
    return (Math.floor(i/27) == Math.floor(j/27) && Math.floor(i%9/3) == Math.floor(j%9/3));
}

sudokuSolver.solve = function (options) {

    // Expect at least one problem
    options.problem = options.problem || 0;

    // Verify if we get a problem
    if (options.problem == 0) {
        console.log("I need a problem");
    } else if (options.problem.length != 81) {
        console.log("A valid sudoku problem should have a length of 81");
    } else {
        solver(options.problem);
    }

    // This is called to solve our game
    function solver(problem) {
        // Save the position of first 0 in our string
        var i = problem.indexOf("0");

        // If i is negative that means we're done
        (i == -1) ? console.log(problem) : 'err'

        // Create a set to save excluded elements
        var excludedElements = new sets.Set();

        // Go throgh the problem
        for (j = 0; j < 81; j++) {
            if (sameRow(i, j) || sameColumn(i, j) || sameBlock(i, j)) {

                // Save in the set the element that is not good
                excludedElements.add(problem[j]);
            }
        }

        // Go and replace the 0 with first available number in asc
        for(var elem = 1; elem <= 9; elem++) {

            // The elem shouldn't be in the excludedElements set
            if (!excludedElements.has(elem.toString())) {

                // Replace the 0 with elem and
                // Call solver with the updated problem
                solver(problem.slice(0, i) + elem + problem.slice(i+1, problem.length));
            }
        }
    }
}

module.exports = sudokuSolver;
<commit_msg>Validate string. Replace spaces<commit_after>// Dependencies
var sets = require('simplesets');

var sudokuSolver = {};

// Some public functions that will help the solver
// Run specs for this functions using jasmine
//
// Check if i is on the same row with j
global.sameRow = function(i, j) {
    return (Math.floor(i/9) == Math.floor(j/9));
}

// Check if i is on the same column with j
global.sameColumn = function(i, j) {
    return ((i - j) % 9 == 0);
}

// Check if i is in the same block with j
global.sameBlock = function(i, j) {
    return (Math.floor(i/27) == Math.floor(j/27) && Math.floor(i%9/3) == Math.floor(j%9/3));
}

sudokuSolver.solve = function (options) {

    // Expect at least one problem
    var problem = options.problem;

    // Replace spaces with nothing
    if (problem && problem.constructor == String) {
        problem = problem.replace (/ /g, "");
    }

    // Verify if we get a problem
    if (!problem || problem.constructor !== String) {
        console.log("Problem mubst be a nonempty string.");
    } else if (problem.length != 81) {
        console.log("A valid sudoku problem should have a length of 81");
    } else {
        solver(problem);
    }

    // This is called to solve our game
    function solver(problem) {
        // Save the position of first 0 in our string
        var i = problem.indexOf("0");

        // If i is negative that means we're done
        (i == -1) ? console.log(problem) : 'err'

        // Create a set to save excluded elements
        var excludedElements = new sets.Set();

        // Go throgh the problem
        for (j = 0; j < 81; j++) {
            if (sameRow(i, j) || sameColumn(i, j) || sameBlock(i, j)) {

                // Save in the set the element that is not good
                excludedElements.add(problem[j]);
            }
        }

        // Go and replace the 0 with first available number in asc
        for(var elem = 1; elem <= 9; elem++) {

            // The elem shouldn't be in the excludedElements set
            if (!excludedElements.has(elem.toString())) {

                // Replace the 0 with elem and
                // Call solver with the updated problem
                solver(problem.slice(0, i) + elem + problem.slice(i+1, problem.length));
            }
        }
    }
}

module.exports = sudokuSolver;

{'fraction_non_alphanumeric': 0.12477718360071301, 'fraction_numerical': 0.012923351158645277, 'mean_word_length': 2.0579019073569484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4831365', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1315, 'n_words': 481}