Chat 4k1

with 20% more anti-xss! :)


xmacejakova (2025-10-05 17:39) kalozrut
vv (2025-10-08 11:15) (function() { // === Vytvorenie kontajnera === const container = document.createElement("div"); container.style.margin = "20px auto"; container.style.width = "fit-content"; container.style.textAlign = "center"; document.body.appendChild(container); // === Vytvorenie tabuľky === const table = document.createElement("table"); table.style.borderCollapse = "collapse"; table.style.fontSize = "20px"; table.style.textAlign = "center"; // === Pomocné funkcie === function isValid(grid, row, col, num) { // Skontroluj riadok a stĺpec for (let i = 0; i < 9; i++) { if (grid[row][i] === num || grid[i][col] === num) return false; } // Skontroluj 3x3 blok const startRow = Math.floor(row / 3) * 3; const startCol = Math.floor(col / 3) * 3; for (let r = startRow; r < startRow + 3; r++) { for (let c = startCol; c < startCol + 3; c++) { if (grid[r][c] === num) return false; } } return true; } // === Generovanie platného Sudoku === const grid = Array(9).fill().map(() => Array(9).fill("")); let attempts = 0; while (attempts < 200 && countFilled(grid) < 30) { const r = Math.floor(Math.random() * 9); const c = Math.floor(Math.random() * 9); const n = Math.floor(Math.random() * 9) + 1; if (!grid[r][c] && isValid(grid, r, c, n)) { grid[r][c] = n; } attempts++; } function countFilled(g) { return g.flat().filter(Boolean).length; } // === Vykreslenie tabuľky === for (let i = 0; i < 9; i++) { const row = document.createElement("tr"); for (let j = 0; j < 9; j++) { const cell = document.createElement("td"); cell.style.width = "40px"; cell.style.height = "40px"; cell.style.border = "1px solid #333"; cell.style.padding = "0"; if (i % 3 === 0) cell.style.borderTop = "2px solid #000"; if (j % 3 === 0) cell.style.borderLeft = "2px solid #000"; if (i === 8) cell.style.borderBottom = "2px solid #000"; if (j === 8) cell.style.borderRight = "2px solid #000"; if (grid[i][j]) { cell.textContent = grid[i][j]; cell.style.backgroundColor = "#f0f0f0"; } else { const input = document.createElement("input"); input.type = "text"; input.maxLength = 1; input.style.width = "38px"; input.style.height = "38px"; input.style.textAlign = "center"; input.style.fontSize = "18px"; input.style.border = "none"; input.style.outline = "none"; input.oninput = (e) => { if (!/^[1-9]?$/.test(e.target.value)) e.target.value = ""; }; cell.appendChild(input); } row.appendChild(cell); } table.appendChild(row); } container.appendChild(table); // === Tlačidlo na vyhodnotenie === const button = document.createElement("button"); button.textContent = "Vyhodnotiť Sudoku"; button.style.marginTop = "20px"; button.style.padding = "10px 20px"; button.style.fontSize = "16px"; button.style.cursor = "pointer"; container.appendChild(button); // === Výsledok === const result = document.createElement("div"); result.style.marginTop = "10px"; result.style.fontWeight = "bold"; container.appendChild(result); // === Funkcia na vyhodnotenie === button.onclick = function() { const values = []; for (let i = 0; i < 9; i++) { values[i] = []; for (let j = 0; j < 9; j++) { const cell = table.rows[i].cells[j]; const val = cell.querySelector("input") ? cell.querySelector("input").value : cell.textContent; values[i][j] = val; } } const unique = arr => { const nums = arr.filter(v => v !== ""); return new Set(nums).size === nums.length; }; let valid = true; for (let i = 0; i < 9; i++) { if (!unique(values[i])) valid = false; } for (let j = 0; j < 9; j++) { const col = values.map(row => row[j]); if (!unique(col)) valid = false; } for (let br = 0; br < 3; br++) { for (let bc = 0; bc < 3; bc++) { const block = []; for (let r = br * 3; r < br * 3 + 3; r++) { for (let c = bc * 3; c < bc * 3 + 3; c++) { block.push(values[r][c]); } } if (!unique(block)) valid = false; } } if (valid) { result.textContent = "✅ Sudoku je zatiaľ bez konfliktov!"; result.style.color = "green"; } else { result.textContent = "❌ Sudoku obsahuje chyby (duplicitné čísla)."; result.style.color = "red"; } }; })();
sc (2025-10-08 11:23)
sudoku (2025-10-08 11:23)
verca (2025-10-08 11:28) sprava 111
verca (2025-10-08 11:35)
aaa (2025-10-08 11:35)
aaa (2025-10-08 11:36)
aaa (2025-10-08 11:36)
qq (2025-10-08 11:37) ahoj
ahoj2 (2025-10-08 11:37)
a (2025-10-08 11:38)
2 (2025-10-08 11:41)
3 (2025-10-08 11:42)
pokus 15 (2025-10-08 11:46)