[NFBCS] Sudoku

Aaron Cannon cannona at fireantproductions.com
Thu Mar 17 03:55:29 UTC 2022


Yeah, that is the tricky part. Fortunately, you can work out a formula that when given a row and column number, will give you the box number. The formula does require that you use integer division, which you have to fake in JS, since all numbers in JS are floats. So you have to use math.floor to simulate it.

But don't try to derive the formula in one shot. Try breaking it down into smaller steps. For example, can you derive a formula to tell you which row of boxes you are dealing with, given a row number? If so, what would that tell you? Well, if you could figure out how to do that, it would tell you that you were either looking at box 0, 1, or 2 for box row 0, boxes 3-5 for box row 1, or 6-8 for box row 2.

Now, if you could also find a formula that, when given a column number, could tell you which box column you were looking at, would that be helpful? Well, if you knew that, then you would be able to determine whether you were in the first box in the box row for box column 0, the 2nd for box column 1, and so on.

Finally, if you could work out both the box column and the box row, then it just becomes a matter of multiplying the box row by 3, and then adding the box column to get the box number.

Another hint: Think of your box rows, box columns, rows, and columns, all in terms of 0-based indexing. It will make the math a lot simpler.

I hope that this is enough to get you started. Once you break everything down, work out a formula for each step, and then put it all together again, you end up with a pretty simple formula that will give you a box number when you plug in a row and column.

Let me know if you need any further help.

Aaron
--
This message was sent from a mobile device


> On Mar 16, 2022, at 17:14, dan.tevelde at comcast.net wrote:
> 
> Hi Aaron,
> 
> Your mention of the boxes is what I'm having trouble grasping. I can easily
> read the contents of the 9 arrays using a Braille display. The arrays are
> separated by brackets which is to be expected. The exercise I am supposed to
> complete requires the user to look at a puzzle to see if it is valid and
> then return true or false. The JavaScript function would be easy to write.
> The tricky part is reading the puzzle to determine if it is valid. It's hard
> to isolate the 3 column boxes.
> 
> Thanks,'
> Dan
> 
> -----Original Message-----
> From: NFBCS <nfbcs-bounces at nfbnet.org> On Behalf Of Aaron Cannon via NFBCS
> Sent: Wednesday, March 16, 2022 3:38 PM
> To: NFB in Computer Science Mailing List <nfbcs at nfbnet.org>
> Cc: Aaron Cannon <cannona at fireantproductions.com>
> Subject: Re: [NFBCS] Sudoku
> 
> Hi.
> 
> I've done this. It's a pretty fun exercise, though in my case, I built a
> solver, which is a subset of the problem you are solving.
> 
> Sudoku puzzles are a grid of 9 by 9 numbers. They are divided up into rows,
> columns, and 9 boxes. You didn't say if you need to validate that a solved
> puzzle is a valid solution, or if an unsolved puzzle is valid because it has
> one and only one valid solution, so I will assume the former.
> Basically, in order to confirm this, you need to check each row, column, and
> box, to confirm that they each have one of each of the digits 1 through 9,
> and that no cells are left blank.
> 
> This is a reasonably simple problem. The trickiest part is figuring out
> which box a given cell is in. box 1 is column 0 through column 2, and row 0
> through row 2. Box 2 is column 3-6, rows 0-2, etc.
> 
> Let me know if I can be of any further assistance.
> 
> Aaron
> _______________________________________________
> NFBCS mailing list
> NFBCS at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> To unsubscribe, change your list options or get your account info for NFBCS:
> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/dan.tevelde%40comcast.net
> 



More information about the NFBCS mailing list