Sudoku with AngularJS

Developer
Size
5,406 Kb
Views
91,080

How do I make an sudoku with angularjs?

What is a sudoku with angularjs? How do you make a sudoku with angularjs? This script and codes were developed by Ye Tsung Ming on 11 July 2022, Monday.

Sudoku with AngularJS Previews

Sudoku with AngularJS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>sudoku with AngularJS</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!DOCTYPE html>
<html ng-app="sudoku"> <head></head> <body> <div class="sudoku" ng-controller="sudokuController as su" pos="0" ng-cloak> <div class="box" ng-repeat="i in su.nine"> <div class="cell" ng-repeat="j in su.nine" contenteditable ng-model="su.array[su.boxmap[i*9+j]]"></div> </div> <button ng-click="su.go()">answer</button> <button ng-click="su.reset()">reset</button> </div> <div class="sudoku" ng-controller="sudokuController as su" pos="1" ng-cloak> <div class="box" ng-repeat="i in su.nine"> <div class="cell" ng-repeat="j in su.nine" contenteditable ng-model="su.array[su.boxmap[i*9+j]]"></div> </div> <button ng-click="su.go()">answer</button> <button ng-click="su.reset()">reset</button> </div> <div class="sudoku" ng-controller="sudokuController as su" pos="2" ng-cloak> <div class="box" ng-repeat="i in su.nine"> <div class="cell" ng-repeat="j in su.nine" contenteditable ng-model="su.array[su.boxmap[i*9+j]]"></div> </div> <button ng-click="su.go()">answer</button> <button ng-click="su.reset()">reset</button> </div> </body>
</html> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js'></script>
<script src='http://jashkenas.github.io/underscore/underscore-min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Sudoku with AngularJS - Script Codes CSS Codes

div { border: black solid 1px; font-size: 18px; text-align: center; float: left;
}
.sudoku { width: 249px; height: 249px; margin-right: 10px;
}
.box { width: 81px; height: 81px;
}
.box .cell { width: 25px; height: 25px;
}
.ng-valid.ng-dirty { color: green;
}
.ng-invalid.ng-dirty { color: red;
}

Sudoku with AngularJS - Script Codes JS Codes

(function() { var app, sudokus, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; sudokus = [[8, '', '', '', '', '', '', '', '', '', '', 3, 6, '', '', '', '', '', '', 7, '', '', 9, '', 2, '', '', '', 5, '', '', '', 7, '', '', '', '', '', '', '', 4, 5, 7, '', '', '', '', '', 1, '', '', '', 3, '', '', '', 1, '', '', '', '', 6, 8, '', '', 8, 5, '', '', '', 1, '', '', 9, '', '', '', '', 4, '', ''], ['', '', '', 7, '', '', '', '', 2, '', 3, '', '', '', 8, '', '', '', 4, '', '', 5, '', '', 3, '', '', '', '', 7, 2, '', '', '', '', 1, '', 1, '', '', '', '', '', 6, '', 8, '', '', '', '', 7, 4, '', '', '', '', 1, '', '', 9, '', '', 5, '', '', '', 6, '', '', '', 2, '', 9, '', '', '', '', 3, '', '', ''], ['', 9, 7, 4, '', '', '', '', '', 4, '', '', '', '', 7, '', 3, '', 3, '', '', '', '', '', '', '', '', 8, '', '', 5, '', 9, '', 1, '', '', '', '', '', '', '', '', '', '', '', 7, '', 1, '', 6, '', '', 8, '', '', 2, '', '', '', '', '', 6, '', 1, '', 6, '', '', '', '', 2, '', '', '', '', '', 5, 3, 8, '']]; app = angular.module('sudoku', []); app.directive('contenteditable', function() { return { restrict: 'A', require: '?ngModel', link: function(scope, ele, attrs, ngmodel) { var array, b, boxmap, i, j; b = scope.$parent.i; j = scope.j % 3 + b % 3 * 3; i = Math.floor(scope.j / 3) + Math.floor(b / 3) * 3; array = scope.$parent.$parent.su.array; boxmap = scope.$parent.$parent.su.boxmap; ngmodel.$render = function() { ele.text(ngmodel.$viewValue || ''); ngmodel.$setValidity('', true); if (!ngmodel.$viewValue) { return ngmodel.$setViewValue(ngmodel.$viewValue); } }; ngmodel.$parsers.push(function(v) { var x; ngmodel.$setValidity('', v === '' || /^[1-9]$/.test(v) && !((function() { var k, len, ref, results; ref = array.slice(i * 9, +(i * 9 + 8) + 1 || 9e9); results = []; for (k = 0, len = ref.length; k < len; k++) { x = ref[k]; if (x === v) { results.push(1); } } return results; })()).length && !((function() { var k, len, ref, results; ref = array.slice(j, 81); results = []; for (k = 0, len = ref.length; k < len; k += 9) { x = ref[k]; if (x === v) { results.push(1); } } return results; })()).length && !((function() { var k, len, ref, results; ref = boxmap.slice(b * 9, +(b * 9 + 8) + 1 || 9e9); results = []; for (k = 0, len = ref.length; k < len; k++) { x = ref[k]; if (array[x] === v) { results.push(1); } } return results; })()).length); if (ngmodel.$valid) { return v; } else { return 0/0; } }); ele.on('keyup change', function() { return ngmodel.$setViewValue(parseInt(ele.text())); }); return null; } }; }); app.controller('sudokuController', function($attrs) { this.array = sudokus[$attrs.pos].slice(0); this.boxmap = [0, 1, 2, 9, 10, 11, 18, 19, 20, 3, 4, 5, 12, 13, 14, 21, 22, 23, 6, 7, 8, 15, 16, 17, 24, 25, 26, 27, 28, 29, 36, 37, 38, 45, 46, 47, 30, 31, 32, 39, 40, 41, 48, 49, 50, 33, 34, 35, 42, 43, 44, 51, 52, 53, 54, 55, 56, 63, 64, 65, 72, 73, 74, 57, 58, 59, 66, 67, 68, 75, 76, 77, 60, 61, 62, 69, 70, 71, 78, 79, 80]; this.getbox = function(index) { var i, k, len, ref, results; ref = this.boxmap.slice(index * 9, +(index * 9 + 8) + 1 || 9e9); results = []; for (k = 0, len = ref.length; k < len; k++) { i = ref[k]; results.push(this.array[i]); } return results; }; this.nine = [0, 1, 2, 3, 4, 5, 6, 7, 8]; this.reset = (function(_this) { return function() { var i, k; for (i = k = 0; k <= 80; i = ++k) { _this.array[i] = sudokus[$attrs.pos][i]; } return null; }; })(this); this.go = function() { var i, k; for (i = k = 0; k <= 80; i = ++k) { if (isNaN(this.array[i])) { this.array[i] = ''; } } this.brute(this.next(0)); return console.log(this.array); }; this.brute = function(pos) { var k, len, nominee, nominees, origin; if (pos > 80) { return null; } origin = this.array.slice(0); if (this.hasslot()) { nominees = this.available(pos); if (nominees === []) { return this.array = origin; } else { for (k = 0, len = nominees.length; k < len; k++) { nominee = nominees[k]; if (this.hasslot()) { this.array = origin; this.array[pos] = nominee; this.brute(this.next(pos + 1)); } else { return; } } } } }; this.next = function(pos) { if (this.array[pos] === '' || pos > 80) { return pos; } else { return this.next(pos + 1); } }; this.available = function(pos) { var box, col, i, row, x, y; x = pos % 9; y = Math.floor(pos / 9); row = (function() { var k, len, ref, results; ref = this.array.slice(y * 9, +(y * 9 + 8) + 1 || 9e9); results = []; for (k = 0, len = ref.length; k < len; k++) { i = ref[k]; results.push(i); } return results; }).call(this); col = (function() { var k, ref, results; results = []; for (i = k = ref = x; k <= 80; i = k += 9) { results.push(this.array[i]); } return results; }).call(this); box = this.getbox(Math.floor(x / 3) + Math.floor(y / 3) * 3); return _.difference([1, 2, 3, 4, 5, 6, 7, 8, 9], _.union(row, col, box)); }; this.hasslot = function() { return indexOf.call(this.array, '') >= 0; }; return null; });
}).call(this);
Sudoku with AngularJS - Script Codes
Sudoku with AngularJS - Script Codes
Home Page Home
Developer Ye Tsung Ming
Username bendwarn
Uploaded July 11, 2022
Rating 3
Size 5,406 Kb
Views 91,080
Do you need developer help for Sudoku with AngularJS?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Ye Tsung Ming (bendwarn) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!