8/14/2023 0 Comments Pseudocode for solving sudoku![]() puzzle def get_column ( self, column_number ): return for row in self. remove ( item ) return possibilities def get_row ( self, row_number ): return self. get_box ( row_number, column_number ) for item in row + column + box : if not isinstance ( item, list ) and item in possibilities : possibilities. ![]() ![]() box_size = 3 def find_possibilities ( self, row_number, column_number ): possibilities = set ( range ( 1, 10 )) row = self. Usually, when we solve them using a computer, we will use nested arrays to represent the Sudoku board like so:Ĭlass SudokuSolver : def _init_ ( self, puzzle ): self. There are lots of approaches to solving these puzzles, many of which can be duplicated by a computer instead of a person. In case you haven't played Sudoku puzzles before, they are number puzzles in which each row, column, and 3x3 square in the puzzle must have the numbers 1-9 represented exactly once. Let's walk through the algorithm and then the implementation. The code isn't perfect, but it will solve pretty much any Sudoku puzzle. Of course, funny things happen in life and I obviously started coding again, but it took me a long time to feel like I was a competent programmer.Īll that being said, a few years later into my programming journey, I decided to retry implementing the Sudoku solving algorithm to prove it to myself that I could implement it now. I ended up getting a C+ on my assignment - one of my worst grades in all of college.Īfter that semester, I abandoned my idea of minoring in computer science, completely quit coding, and stuck to what I thought I was good at - writing and politics. By the time the project was due, my solution worked for some of the test cases but not all of them. Again, I spent countless hours on the assignment trying to get the code working. One problem in particular really got me - we were supposed to build a program in C++ that would solve any Sudoku problem. I spent many all-nighters working on projects and studying for the exams. I felt completely lost in pretty much every lesson. My pride was the only thing keeping me in the class. We even changed classrooms from a lecture hall to a break out room. It quickly became obvious that the professors were trying to use the class to filter out students - so many of the enrollees on day one made it through the semester. The class was taught in C++, which, unbeknown to me was supposed to be learned over the summer before the class. The next semester, I enrolled in a Data Structures and Algorithms course which was next in the computer science sequence. I quickly decided to minor in computer science, and I just wanted to write more code. It honestly came pretty easy to me, and I had a ton of fun. Over the course of that class, I built a Tic Tac Toe script with a GUI to input pieces and a Flappy Bird clone. They had printed the code and just had us type it in and run it - I was immediately hooked. So coding was brand new to me when I took that Python class in college.Īs soon as I walked into the classroom, they had us type Python code into Idle, a text editor that comes with the Python language. My high school definitely did not have any coding classes, they barely had functioning computers! I didn't play video games or engage in activities that traditionally lead to kids learning how to code either. I thought we would learn how to use Microsoft Word and Excel - I genuinely had no idea what code was. I had an untraditional path to writing code - I randomly enrolled in a computer science class during my sophomore year of college because I had an extra credit hour and I was curious what it was about. ![]() This story starts a few years ago in a college computer science classroom. If you are just here for the code and explanation, jump to the The Initial Approach header! Quick warning, this article will be part technical, part personal story, part cultural critique.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |