Code Monkey home page Code Monkey logo

sudoku-solver-py's Introduction

sudoku-solver-py

soduku-solver-py is a simple program I challenged myself to create in 6 hours in python. Python is a language I need the most practice with, so I felt like this would be a good project to challenge that. This was a timed challenge, so there are most likely bugs, and it is not efficient at all.

How it works

You can View The Demo here, but basically heres the meat of the application.

  • An object Board is generated which contains self.board and self.backup, with various helper classes such as Board.restoreBackup() and Board.canPlaceNumber.
  • The self.board object is an array of 9 1 x 9 arrays, for example:
     [[2,8,0,0,0,0,0,0,1],
     [0,0,0,8,0,1,0,0,4],
     [0,0,4,0,7,0,3,0,0],
     [0,2,0,0,5,0,0,6,0],
     [0,0,3,1,0,9,7,0,0],
     [0,1,0,0,8,0,0,5,0],
     [0,0,1,0,6,0,8,0,0],
     [5,0,0,2,0,3,0,0,0],
     [9,0,0,0,0,0,0,1,6]]
    
  • The program then generates an array potentialBoardValues, and assigns each blank space an array with all numbers that could be possible numbers for that space.
  • We loop through potentialBoardValues and find where only 1 value can be placed there. This action is repeated until there are no more guaranteed values.
  • We now recursively loop through potentialBoardValues , assigning numbers and searching for singular possibilities, reverting to a backup board when an invalid board is encountered.
    • At some point the board will be solved, which can take anywhere from 1 second to 1 minute, since its not very efficient at all.

Todo

If I ever do revisit this project, I need to revamp the correction system so it goes back to the furthest correct point. Right now, we backup to the beginning when encountering an invalid board, which exponentially increases solve times.

Credits

This project is completely coded by Jonathan Becker, using no external libraries.

sudoku-solver-py's People

Contributors

jon-becker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

yoyoyoshi81

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.