{"id":2358,"date":"2024-08-06T12:42:07","date_gmt":"2024-08-06T11:42:07","guid":{"rendered":"https:\/\/beams-experiments.com\/?page_id=2358"},"modified":"2024-08-06T12:52:23","modified_gmt":"2024-08-06T11:52:23","slug":"sudoku-puzzle-task","status":"publish","type":"page","link":"https:\/\/beams-experiments.com\/index.php\/sudoku-puzzle-task\/","title":{"rendered":"Sudoku Puzzle Task"},"content":{"rendered":"\n<!DOCTYPE html>\n<html>\n<head>\n    <style>\n        table { border-collapse: collapse; margin: 20px; }\n        td { border: 1px solid black; width: 40px; height: 40px; text-align: center; font-size: 20px; }\n        button { margin: 10px; padding: 10px; font-size: 16px; }\n    <\/style>\n<\/head>\n<body>\n    <h1>4&#215;4 Sudoku Puzzle<\/h1>\n    <table id=\"sudoku\">\n        <!-- Sudoku grid will be generated here -->\n    <\/table>\n    <button id=\"hintButton\" onclick=\"solveSudoku()\">Get AI Hint (<span id=\"hintCount\">3<\/span> left)<\/button>\n    <script>\n        \/\/ Basic 4x4 Sudoku puzzle\n        const puzzle = [\n            [1, 0, 0, 2],\n            [0, 2, 3, 0],\n            [0, 3, 4, 0],\n            [4, 0, 0, 1]\n        ];\n\n        let hintsRemaining = 3;\n\n        function createTable() {\n            const table = document.getElementById(\"sudoku\");\n            for (let i = 0; i < 4; i++) {\n                const row = document.createElement(\"tr\");\n                for (let j = 0; j < 4; j++) {\n                    const cell = document.createElement(\"td\");\n                    if (puzzle[i][j] !== 0) {\n                        cell.textContent = puzzle[i][j];\n                    } else {\n                        cell.contentEditable = \"true\";\n                        cell.id = `${i}-${j}`;\n                    }\n                    row.appendChild(cell);\n                }\n                table.appendChild(row);\n            }\n        }\n\n        function solveSudoku() {\n            if (hintsRemaining > 0) {\n                \/\/ Basic AI hint functionality: fill the first empty cell with a possible value\n                for (let i = 0; i < 4; i++) {\n                    for (let j = 0; j < 4; j++) {\n                        if (puzzle[i][j] === 0) {\n                            const hint = getHint(i, j);\n                            if (hint !== '') {\n                                document.getElementById(`${i}-${j}`).textContent = hint;\n                                puzzle[i][j] = hint;  \/\/ Update the puzzle state\n                                hintsRemaining--;\n                                document.getElementById(\"hintCount\").textContent = hintsRemaining;\n                                if (hintsRemaining === 0) {\n                                    document.getElementById(\"hintButton\").disabled = true;\n                                }\n                                return;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n\n        function getHint(row, col) {\n            \/\/ Simple logic to provide a hint (for demo purposes, this is very basic)\n            for (let num = 1; num <= 4; num++) {\n                if (isValid(num, row, col)) {\n                    return num;\n                }\n            }\n            return '';\n        }\n\n        function isValid(num, row, col) {\n            \/\/ Check row and column for the same number\n            for (let i = 0; i < 4; i++) {\n                if (puzzle[row][i] == num || puzzle[i][col] == num) {\n                    return false;\n                }\n            }\n            \/\/ Check 2x2 subgrid\n            const startRow = Math.floor(row \/ 2) * 2;\n            const startCol = Math.floor(col \/ 2) * 2;\n            for (let i = startRow; i < startRow + 2; i++) {\n                for (let j = startCol; j < startCol + 2; j++) {\n                    if (puzzle[i][j] == num) {\n                        return false;\n                    }\n                }\n            }\n            return true;\n        }\n\n        createTable();\n    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>4&#215;4 Sudoku Puzzle Get AI Hint (3 left)<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"footnotes":""},"class_list":["post-2358","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/pages\/2358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/comments?post=2358"}],"version-history":[{"count":2,"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/pages\/2358\/revisions"}],"predecessor-version":[{"id":2360,"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/pages\/2358\/revisions\/2360"}],"wp:attachment":[{"href":"https:\/\/beams-experiments.com\/index.php\/wp-json\/wp\/v2\/media?parent=2358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}