← Back to Upcase

Prime Programming Challenge #2


(Joel Quenneville) #1

Hi all,

Big news! Our second exercise is out. This one is targeted at advanced beginners.

Make no mistake: it’s not a sudoku solver, it’s a sudoku validator.

Curious? Check it out: https://github.com/thoughtbot/sudoku_validator

Have fun!

Joël


(Ben Orenstein) #2

This topic is now pinned. It will appear at the top of its category until it is either unpinned by a moderator, or the Clear Pin button is pressed.


(charlieanna) #3

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.


(charlieanna) #4

@benorenstein how do I parse the fixtures? Should I create my own data structure and feed in the invalid and valid values?


(Joel Quenneville) #5

@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.


(Alexey Zabelin) #6

Hello everyone!

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?

Thank you.


(David Pedersen) #7

I think just taking a brute force approach is the way to go. A sudoko board is never that big. So I would just test all rows, columns, and squares.


(Joel Quenneville) #8

@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 program must be a ruby executable. Practicing Ruby has good article on building unix-style command-line apps
  • 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.

(Alexey Zabelin) #9

Thanks, I’ll do that!


(Alexey Zabelin) #10

Woah, thank you for this post, I’ll look into all of those things!