Alexandre P. Levasseur
See other posts from Programmers
or by Alexandre P. Levasseur
Published on 2012-10-27T03:48:09Z Indexed on 2012/10/27 5:16 UTC
Read the original article Hit count: 355
I have started an introductory Java class and the material is absolutely horrendous and I have to get excellent grades to be accepted into the master's degree, hence my very beginner question:
In my assignment I have to write algorithms (no pseudo-code yet) to solve a board game (Sudoku). Essentially, the notes say that an algorithm is specification of the input(s), the output(s) and the treatments applied to the input to get the output. My question lies on the wording of algorithms because I could probably code it but I can't seem to put it on paper in a coherent way.
The game has a 9x9 board and one of the algorithms to write has to find the solution by looking at 3 squares (either horizontal or vertical) and see if one of the three sub-squares match the number you are looking for. If none match then the number you are looking to place is in one of the other 2 set of 3 sub-squares (see image to get a better idea).
I really can't get my head around how to formulate the solution into the terms described above or maybe it's just too simple, here's what I was thinking:
Input: A 2-dimensional set of data of size 9 by 9 to be solved and a number to search for.
Ouput: A 2-dimensional set of data of size 9 by 9 either solved or partially solved.
Treatment: Scan each set of 3x9 and 9x3 squares. For each line or column of a 3x3 square check if the number matches a line (or column). If it does then move to the next line (or column). If not then proceed to the next 3x3 square in the same line (or column). Rinse and repeat.
Does that make sense as an algorithm written in plain english ? I'm not looking for an answer to the algorithm per se but rather on the formulation of algorithms in plain english.
© Programmers or respective owner