{"id":1819,"date":"2025-12-05T05:30:10","date_gmt":"2025-12-05T05:30:10","guid":{"rendered":"https:\/\/clubvivremieux.com\/?page_id=1819"},"modified":"2025-12-05T06:06:25","modified_gmt":"2025-12-05T06:06:25","slug":"1819-2","status":"publish","type":"page","link":"https:\/\/clubvivremieux.com\/index.php\/1819-2\/","title":{"rendered":"SUDOKU"},"content":{"rendered":"\n<div class=\"sudoku-container\">\n  <div>\n    Niveau :\n    <select id=\"difficulty\">\n      <option value=\"35\">Facile<\/option>\n      <option value=\"45\">Moyen<\/option>\n      <option value=\"55\">Difficile<\/option>\n    <\/select>\n  <\/div>\n\n  <div id=\"sudoku\" class=\"sudoku-grid\"><\/div>\n\n  <div class=\"controls\">\n    <button class=\"btn\" id=\"newGameBtn\">Nouvelle grille<\/button>\n    <button class=\"btn\" id=\"checkBtn\">V\u00e9rifier la grille<\/button>\n  <\/div>\n\n  <div class=\"timer\">\u23f1 Temps : <span id=\"time\">00:00<\/span><\/div>\n<\/div>\n\n<style>\n.sudoku-container { display: inline-block; padding: 20px; background: #f8f8f8; border-radius:10px; border:1px solid #ccc; }\n.sudoku-grid { display: grid; grid-template-columns: repeat(9, 40px); gap:0; border:2px solid black; }\n.cell { width:40px; height:40px; font-size:22px; text-align:center; border:1px solid #aaa; }\n.cell[readonly] { background:#e2e2e2; font-weight:bold; }\n.bold-border-top { border-top:3px solid black !important; }\n.bold-border-left { border-left:3px solid black !important; }\n.bold-border-right { border-right:3px solid black !important; }\n.bold-border-bottom { border-bottom:3px solid black !important; }\n.error { background:#ffb6b6 !important; }\n.duplicate { background:#ffd27f !important; }\n.controls { margin-top:15px; display:flex; gap:10px; flex-wrap:wrap; }\n.btn { padding:8px 15px; font-size:16px; cursor:pointer; background:#0073aa; color:white; border:none; border-radius:5px; }\n.timer { font-size:18px; margin-top:10px; }\n<\/style>\n\n<script>\ndocument.addEventListener(\"DOMContentLoaded\", function() {\n\nlet timerInterval;\nlet startTime;\nlet solutionGrid;\nlet currentPuzzle;\n\nfunction startTimer() {\n  clearInterval(timerInterval);\n  startTime = Date.now();\n  timerInterval = setInterval(() => {\n    const elapsed = Math.floor((Date.now() - startTime)\/1000);\n    const min = String(Math.floor(elapsed\/60)).padStart(2,'0');\n    const sec = String(elapsed%60).padStart(2,'0');\n    document.getElementById(\"time\").textContent = `${min}:${sec}`;\n  }, 500);\n}\n\n\/* Sudoku logic *\/\nfunction generateEmptyGrid() { return Array.from({length:9},()=>Array(9).fill(0)); }\nfunction shuffle(arr) { return arr.sort(()=>Math.random()-0.5); }\nfunction isSafe(grid,r,c,num){\n  for(let i=0;i<9;i++){ if(grid[r][i]===num||grid[i][c]===num) return false; }\n  const rs=r-r%3, cs=c-c%3;\n  for(let i=0;i<3;i++){for(let j=0;j<3;j++){if(grid[rs+i][cs+j]===num)return false;}}\n  return true;\n}\nfunction solve(grid){\n  for(let r=0;r<9;r++){for(let c=0;c<9;c++){if(grid[r][c]===0){\n    for(let num of shuffle([1,2,3,4,5,6,7,8,9])){if(isSafe(grid,r,c,num)){grid[r][c]=num;if(solve(grid)) return true; grid[r][c]=0;}}\n    return false;\n  }}}\n  return true;\n}\nfunction removeNumbers(grid, holes){\n  while(holes>0){let r=Math.floor(Math.random()*9), c=Math.floor(Math.random()*9);\n  if(grid[r][c]!==0){grid[r][c]=0; holes--;}}\n}\n\n\/* Display *\/\nfunction display(puzzle){\n  const container=document.getElementById(\"sudoku\");\n  container.innerHTML=\"\";\n  puzzle.forEach((row,r)=>{\n    row.forEach((num,c)=>{\n      const cell=document.createElement(\"input\");\n      cell.className=\"cell\";\n      if(r%3===0) cell.classList.add(\"bold-border-top\");\n      if(c%3===0) cell.classList.add(\"bold-border-left\");\n      if(c===8) cell.classList.add(\"bold-border-right\");\n      if(r===8) cell.classList.add(\"bold-border-bottom\");\n      if(num!==0){cell.value=num; cell.readOnly=true;}\n      else{\n        cell.addEventListener(\"input\", ()=>{\n          cell.value=cell.value.replace(\/[^1-9]\/g,\"\");\n          saveProgress(); checkDuplicates();\n        });\n      }\n      container.appendChild(cell);\n    });\n  });\n}\n\nfunction getCurrentGrid(){\n  const cells=document.querySelectorAll(\".cell\");\n  let grid=generateEmptyGrid();\n  cells.forEach((cell,i)=>{\n    const r=Math.floor(i\/9), c=i%9;\n    grid[r][c]=cell.value?parseInt(cell.value):0;\n  });\n  return grid;\n}\n\nfunction checkDuplicates(){\n  document.querySelectorAll(\".cell\").forEach(c=>c.classList.remove(\"duplicate\"));\n  const grid=getCurrentGrid();\n  for(let r=0;r<9;r++){for(let c=0;c<9;c++){\n    const val=grid[r][c]; if(!val) continue;\n    for(let i=0;i<9;i++){if(i!==c&#038;&#038;grid[r][i]===val) markDuplicate(r,c); if(i!==r&#038;&#038;grid[i][c]===val) markDuplicate(r,c);}\n    const rs=r-r%3, cs=c-c%3;\n    for(let i=0;i<3;i++){for(let j=0;j<3;j++){const rr=rs+i,cc=cs+j; if((rr!==r||cc!==c)&#038;&#038;grid[rr][cc]===val) markDuplicate(r,c);}}\n  }}\n}\n\nfunction markDuplicate(r,c){document.querySelectorAll(\".cell\")[r*9+c].classList.add(\"duplicate\");}\n\nfunction saveProgress(){\n  localStorage.setItem(\"sudoku_puzzle\", JSON.stringify(currentPuzzle));\n  localStorage.setItem(\"sudoku_progress\", JSON.stringify(getCurrentGrid()));\n}\n\nfunction loadProgress(){\n  const puzzle=localStorage.getItem(\"sudoku_puzzle\");\n  const progress=localStorage.getItem(\"sudoku_progress\");\n  if(puzzle &#038;&#038; progress){currentPuzzle=JSON.parse(puzzle); display(JSON.parse(progress)); checkDuplicates(); startTimer(); return true;}\n  return false;\n}\n\n\/* Check solution *\/\nfunction checkGrid(){\n  const grid=getCurrentGrid();\n  let ok=true;\n  for(let r=0;r<9;r++){for(let c=0;c<9;c++){if(grid[r][c]!==solutionGrid[r][c]) ok=false;}}\n  if(ok) alert(\"\ud83c\udf89 Bravo, grille compl\u00e9t\u00e9e !\");\n  else alert(\"\u274c Il reste des erreurs.\");\n}\n\n\/* New game *\/\nfunction newGame(){\n  clearInterval(timerInterval);\n  const diff=parseInt(document.getElementById(\"difficulty\").value);\n  let grid=generateEmptyGrid();\n  solve(grid);\n  solutionGrid=JSON.parse(JSON.stringify(grid));\n  removeNumbers(grid,diff);\n  currentPuzzle=JSON.parse(JSON.stringify(grid));\n  display(grid);\n  startTimer();\n  saveProgress();\n}\n\n\/* Buttons *\/\ndocument.getElementById(\"newGameBtn\").addEventListener(\"click\", newGame);\ndocument.getElementById(\"checkBtn\").addEventListener(\"click\", checkGrid);\n\n\/* Load saved game or new *\/\nif(!loadProgress()) newGame();\n\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Niveau : FacileMoyenDifficile Nouvelle grille V\u00e9rifier la grille \u23f1 Temps : 00:00<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1819","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/pages\/1819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/comments?post=1819"}],"version-history":[{"count":12,"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/pages\/1819\/revisions"}],"predecessor-version":[{"id":1834,"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/pages\/1819\/revisions\/1834"}],"wp:attachment":[{"href":"https:\/\/clubvivremieux.com\/index.php\/wp-json\/wp\/v2\/media?parent=1819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}