{"id":16293276,"url":"https://github.com/pocketjoso/sudokujs","last_synced_at":"2025-07-01T01:36:06.317Z","repository":{"id":15741137,"uuid":"18479713","full_name":"pocketjoso/sudokuJS","owner":"pocketjoso","description":"JavaScript step-by-step Sudoku solver and board generator","archived":false,"fork":false,"pushed_at":"2016-12-03T13:47:59.000Z","size":47,"stargazers_count":221,"open_issues_count":3,"forks_count":85,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-09T01:44:38.417Z","etag":null,"topics":["board-generation","javascript","sudoku","sudoku-board","sudoku-puzzle"],"latest_commit_sha":null,"homepage":"https://jonassebastianohlsson.com/sudoku/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pocketjoso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-06T00:28:52.000Z","updated_at":"2025-04-17T17:13:18.000Z","dependencies_parsed_at":"2022-07-20T22:54:45.214Z","dependency_job_id":null,"html_url":"https://github.com/pocketjoso/sudokuJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pocketjoso/sudokuJS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketjoso%2FsudokuJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketjoso%2FsudokuJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketjoso%2FsudokuJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketjoso%2FsudokuJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pocketjoso","download_url":"https://codeload.github.com/pocketjoso/sudokuJS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocketjoso%2FsudokuJS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262879844,"owners_count":23378686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["board-generation","javascript","sudoku","sudoku-board","sudoku-puzzle"],"created_at":"2024-10-10T20:10:42.207Z","updated_at":"2025-07-01T01:36:06.294Z","avatar_url":"https://github.com/pocketjoso.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#SudokuJS\n##JavaScript Sudoku solver\n\nLive demo on: https://jonassebastianohlsson.com/sudoku/\n\nSudokuJS has a step by step solver that implements basic strategies,\nenough to solve (non evil) newspaper sudoku puzzles. The solver is built\nto mimic humans in that it attempts strategies in order from easiest to most\ndifficult, in each step. So if you're stuck with a puzzle this solver will show\nyou the minimal next step to continue.\n\nSudokuJS comes with a basic GUI for the sudoku board - the board is rendered on the screen,\nand the board cells listen for keyboard input from a user.\n\nSudokuJS can generate sudoku puzzles of the same difficulties that it can solve,\nranging from Easy to Very hard.\n\nSudokuJS currently requires jQuery (on TODO to remove this dependency).\n\n### Usage\n\n#### Initialization\n\t\u003cscript src='sudokuJS.js'\u003e\u003c/script\u003e\n    \u003clink rel='stylesheet' href='sudokuJS.css' /\u003e\n\n    \u003cdiv id='sudoku'\u003e\u003c/div\u003e\n\n    \u003cscript\u003e\n\n    var mySudokuJS = $(\"#sudoku\").sudokuJS({\n        difficulty: \"medium\" (\"easy\"|\"medium\"|\"hard\"|\"very hard\")\n    });\n    \u003c/script\u003e\n\nYou can also pass in your own board:\n\n\t//array representing a standard sudoku puzzle of size 9\n\t//use space for empty cells\n\tvar board = [\n\t\t, , ,4, ,8, ,2,9\n\t\t, , , , , , , , ,4\n\t\t,8,5, , ,2, , , ,7\n\t\t, , ,8,3,7,4,2, ,\n\t\t, ,2, , , , , , ,\n\t\t, , ,3,2,6,1,7, ,\n\t\t, , , , ,9,3,6,1,2\n\t\t,2, , , , , ,4, ,3\n\t\t,1,3, ,6,4,2, ,7,undefined\n\t]\n\t//NOTE: if last cell of board is empty, 'undefined' has to be used as value!\n\tvar mySudokuJS = $(\"#sudoku\").sudokuJS({\n\t\t\tboard: board\n\t});\n\n#### Solving\nLet `SudokuJS` solve your puzzle - either step by step, or all in one go:\n\n\tmySudokuJS.solveStep();\n\tmySudokuJS.solveAll();\n\n#### Analyzing the board\nThe solver can tell you info about the board.\n\n\tvar data = mySudokuJS.analyzeBoard();\n\n\t//data.error -- board is incorrect\n\t//data.finished === false -- board can't be solved because it requires more advanced strategies\n\n\t//if no error, and data.finished === true\n\t//data.level -- \"easy\"|\"medium\"|\"hard\"\n\t//data.score -- int [experimental]\n\t//data.usedStrategies -- [{title, freq}, ..],ranked by difficulty, easiest first\n\n#### Board Generation\n`SudokuJS` generate new sudoku puzzles on init when no board is passed in,\n and on `generateBoard` calls:\n\n\tmySudokuJS.generateBoard('easy');\n\tmySudokuJS.generateBoard('medium');\n\tmySudokuJS.generateBoard('hard');\n\tmySudokuJS.generateBoard('very hard');\n\nThe current implementation for board generation cannot guarantee hard or\nvery hard puzzles generated on every try, so instead it continues over and over\nuntil is has succeeded. This means loading a very hard board can sometimes\ntake up to a few seconds.\n\n`generateBoard` accepts a `callback` function as a second paramater, that gets called when the new board is ready.\n\n#### Candidates\nCandidates are hidden when a board loads. To show/hide candidates:\n\n\tmySudokuJS.showCandidates();\n\tmySudokuJS.hideCandidates();\n\nSudokuJS automatically removes impossible candidates on showCandidates();\ncandidates that can be eliminated via visualElimination (number already exists in same house).\n\nCandidates can be edited on the board by setting SudokuJS to candidate editing mode:\n\n\tmySudokuJS.setEditingCandidates(true);\n\nInput changes on board cells will now toggle the candidates rather than changes the value.\n\n#### Clear board\nUseful before entering new puzzle, if using keyboard input in the GUI.\n\n\tmySudokuJS.clearBoard();\n\n#### Get/Set board\nGet the board and save it away if you want. Set a new board and play with that one instead.\nSetting automatically resets everything back to init state.\n\n\tmySudokuJS.getBoard();\n\n\tvar newBoard = [\n\t\t...\n\t]\n\n\tmySudokuJS.setBoard(newBoard);\n\n\n\n### Callbacks\n\n#### boardUpdatedFn\nFires whenever the board is updated, whether by user or solver.\n\n\t $(\"#sudoku\").sudokuJS({\n\t\tboard: board\n\t\t,boardUpdatedFn: function(data){\n\t\t\t//data.cause: \"user input\" | name of strategy used\n\t\t\t//data.cellsUpdated: [] of indexes for cells updated\n\t\t\talert(\"board was updated!\");\n\t\t}\n\t});\n\n#### boardFinishedFn\nFires when the board has been completed.\n\n\t $(\"#sudoku\").sudokuJS({\n\t\tboard: board\n\t\t,boardFinishedFn: function(data){\n\t\t\t//ONLY IF board was solved by solver:\n\t\t\t//data.difficultyInfo {\n\t\t\t//\tlevel: \"easy\", \"medium\", \"hard\"\n\t\t\t//\t,score: int [experimental]\n\t\t\t//}\n\t\t\talert(\"board was finished!\");\n\t\t}\n\t});\n\n\n#### boardErrorFn\nFires whenever the board is found to be incorrect, f.e. if solver detects there is no solution to board, or if passed in board is of invalid size.\n\n\t $(\"#sudoku\").sudokuJS({\n\t\tboard: board\n\t\t,boardErrorFn: function(data){\n\t\t\t//data.msg -- f.e. \"board incorrect\"\n\t\t\talert(\"board error!\");\n\t\t}\n\t});\n\n#### candidateShowToggleFn\n The solver automatically switches to showing candidates when a solve step was invoked which only updated the candidates on the board. To catch this change (for updating UI, etc), there is a callback:\n\n\t $(\"#sudoku\").sudokuJS({\n\t\tboard: board\n\t\t,candidateShowToggleFn: function(showingBoolean){\n\t\t\talert(\"candidates showing: \" + showingBoolean); //true|false\n\t\t}\n\t}\n\n### Extra\nThe solver is board size agnostic, so you can pass in any valid sudoku sized board (f.e. 4x4, 9x9, 16x16) - however the CSS included only handles 9x9 boards. Currently you can't change boardSize after init.\n\n### License\nMIT\n\n### Changelog\n0.4.5 boardSize option, now working. Demos for board sizes\n0.4.0 Candidate editing mode  \n0.3.0 Board generator, easy - very hard  \n0.2.0 Simple UI and better interface  \n0.1.0 Step by step sudoku solver  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocketjoso%2Fsudokujs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpocketjoso%2Fsudokujs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocketjoso%2Fsudokujs/lists"}