Hartismere School

Est. 1451. An outstanding coeducational secondary school & sixth form college and England's first academy

Home Login

Computerphile Sudoku Python

grid = [
       [ 5, 0, 0, 1, 0, 0, 7, 0, 0 ],
       [ 0, 2, 0, 0, 0, 7, 1, 0, 0 ],
       [ 3, 0, 1, 4, 0, 0, 8, 5, 2 ],
       [ 6, 1, 0, 5, 7, 2, 4, 0, 8 ],
       [ 0, 0, 2, 9, 6, 0, 0, 0, 0 ],
       [ 0, 4, 0, 0, 3, 0, 6, 2, 7 ],
       [ 4, 5, 9, 0, 8, 0, 0, 7, 0 ],
       [ 1, 3, 0, 0, 0, 0, 9, 8, 6 ],
       [ 2, 0, 0, 0, 1, 0, 0, 4, 3 ]
   ]
   
def possible(y,x,n):
   for i in range(0,9):
       if grid[y][i] == n:
           return False
   for i in range(0,9):
       if grid[i][x] == n:
           return False
   x0 = (x//3)*3
   y0 = (y//3)*3
   for i in range(0,3):
       for j in range(0,3):
           if grid[y0+i][x0+j] == n:
               return False
   return True
   
def solve():
   print("solving")
   for y in range(9):
       for x in range(9):
           if grid[y][x] == 0:
               for n in range(1,10):
                   if possible(y,x,n):
                       grid[y][x] = n
                       solve()
                       grid[y][x] = 0
               return
   printGrid()
   input()
   
def printGrid() : 
   for n in range(0,9):
       print(grid[n])
       
solve()

Documents

Explore...

Hartismere Website :: A History :: 1999

Documentary: making of Do the Right Thing

6000 extras at Gorleston beach - and we were a part of it!

C# Cook Book // Quiz (Console)

1.3 Computer networks, connections and protocols Flashcards | Quizlet

C# Cook Book // Conversation (Console)

Essential programming skills to learn

GCSE Computer Science

Hartismere Website :: A History :: 2016

Hartismere Website :: A History :: 2001 (1st Ed)

New...

Teacher of Health & Social Care

Online safety newsletters

Friends of Hartismere School

Local Governing Body Information

Teacher of Sociology

Useful Careers Websites

Do the Right Thing Scene Analysis

Friends of Hartismere School - Car Boot Sale

Discover...

Python Programming Computerphile Videos Computer Science Chemistry The Stories We Tell ABU Hartismere Crashcourse Website Statutory Information CPU Archive KS4 Chemistry Wellbeing C# Recipes A Level Computing GCSE CS Internet Repl.It

Uh-oh - we were unable to load our website on your browser so we're showing you a plain HTML version.

We use many features found in modern browsers and regrettably yours seems incompatible.

However this legacy version contains (very, very nearly) all the same content. Each page is rendered on our server and doesn't rely on any browser features except the odd font. It doesn't even need Javascript or fancy CSS. It's like being in 1995!

Your browser is reporting itself to us as Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com). Please consider updating your browser to make the most of our website.

If you would like to try our proper website again - you can do so here...