Thanks @joelq for the question. I have started to write my solution. The first question screencast is helping me a lot since this will be my first TDD.
@ankur_kothari you probably want some type of parser object that can read in the file and create a Sudoku object. The Sudoku object would know whether it was valid or not, possibly responding to a valid? method. The parser shouldn’t know about the concept of valid/invalid. It’s single responsibility should be converting .sudoku files into objects.
I know I am late to the party, but I’ve only found this exercise today and wanted to give it a try.
But once I’ve looked at the requirements and such I realized just how lost I am at figuring out a way to tackle this.
Not sure at all whether I should check all the rows, columns and smaller grids to solve this or if there is some other way to go about it. I guess what I am asking is, are there any particular subjects related to this assignment I should study to understand the thought process needed for this?
@Alexey_Zabelin You are correct. A grid is valid if there are no duplicates in any of the rows, columns, or subgrids. You will want to parse the .sudoku files into ruby objects and then ask those objects if all rows, columns and subgrids are valid. A Sudoku grid has 9 rows, 9 columns and 9 subgrids for a total of 27 validations to check.
Some technical subjects that might help on this project:
Rows, columns, subgrids, and even the main Sudoku grid itself are all collections. The Enumerable module gives you a lot of goodies for dealing with collections.
This project gets input from the command line, reads a file, and outputs to the command line. I recently wrote an article on Input/Output in Ruby. You might also want to check out the documentation for the File class
Some people have used the Matrix class to model the Sudoku grid. 2d Arrays are another approach. Alternatively, you could just build a Grid that holds collections of Rows, Columns, and SubGrids.
Regular expressions may come in handy while parsing the file. Check out our Primer on Regular Expressions as a reference.