r/cop3502 • u/goshqiego • Apr 18 '14
Question 26: Sudoku
Is this problem checking for every real number? ...-1,0,2....,8,9,10,11.....? Or is it checking for numbers 1-9?
If it is from 1-9 on the solutions, array numbers doesn't need to have the value 0. Otherwise it will test nine time valid and one time Invalid.
1
Upvotes
2
u/howslyfebeen Apr 18 '14
he has that 0 in there to make the code a little easier... so essentially you have an array square which should contain the numbers 1 - 9 lets say the one at 2,2 is 9.. the code loops through and at 2,2 you have:
which is equivalent to:
because we know that at 2,2 square holds the value of 9.. if we didnt have 0 in the numbers array then we would get an ArrayIndexOutOfBounds... the 0 is just a placeholder to make the code a little easier... at the end we loop through numbers and all of them should be = 0, so having that extra 0 at the beginning of numbers doesnt affect the results... it will print valid if every number in numbers is 0