Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('app', []);
- angular.module('app').config(['$controllerProvider', function($controllerProvider) {
- $controllerProvider.allowGlobals();
- }]);
- function emptyRow() {
- return [0, 0, 0, 0, 0, 0, 0, 0, 0];
- }
- function emptyMatrix() {
- var sudokuMatrix = [];
- for (var i = 0; i < 9; i++) {
- sudokuMatrix[i] = emptyRow();
- }
- return sudokuMatrix;
- }
- function updateValue(sudokuMatrix, row, col, val) {
- row = parseInt(row);
- col = parseInt(col);
- val = parseInt(val);
- sudokuMatrix[row][col] = val;
- }
- function exampleMatrix() {
- matrix = emptyMatrix();
- updateValue(matrix, 0, 2, 6);
- updateValue(matrix, 0, 3, 3);
- updateValue(matrix, 0, 4, 2);
- updateValue(matrix, 1, 2, 1);
- updateValue(matrix, 1, 5, 5);
- updateValue(matrix, 1, 6, 3);
- updateValue(matrix, 1, 7, 6);
- updateValue(matrix, 2, 0, 9);
- updateValue(matrix, 2, 1, 4);
- updateValue(matrix, 2, 3, 6);
- updateValue(matrix, 3, 2, 4);
- updateValue(matrix, 4, 0, 8);
- updateValue(matrix, 4, 1, 7);
- updateValue(matrix, 4, 3, 1);
- updateValue(matrix, 4, 4, 3);
- updateValue(matrix, 4, 5, 4);
- updateValue(matrix, 4, 7, 5);
- updateValue(matrix, 4, 8, 6);
- updateValue(matrix, 5, 6, 1);
- updateValue(matrix, 6, 5, 9);
- updateValue(matrix, 6, 7, 4);
- updateValue(matrix, 6, 8, 7);
- updateValue(matrix, 7, 1, 1);
- updateValue(matrix, 7, 2, 7);
- updateValue(matrix, 7, 3, 5);
- updateValue(matrix, 7, 6, 2);
- updateValue(matrix, 8, 4, 7);
- updateValue(matrix, 8, 5, 2);
- updateValue(matrix, 8, 6, 5);
- return matrix;
- }
- function TestController($scope) {
- $scope.matrix = exampleMatrix();
- $scope.updateValue = updateValue;
- $scope.getMatrixVal = function getMatrixVal(row, col) {
- return $scope.matrix[row][col];
- };
- }
Add Comment
Please, Sign In to add comment