Advertisement
Guest User

Sudoku

a guest
Feb 27th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.44 KB | None | 0 0
  1. Sudoku Pseudocode:
  2.  
  3. I. Create Board
  4.     A. Split the input string
  5.         string.split("")
  6.     B. Convert into an array
  7.         [master array]
  8. II. Find empty cell
  9.     A. Find first "-" in master array
  10.     B. Define the variable
  11.         current index = index # this is our unique id number!
  12. III. Collect Corresponding Filled Cells
  13.     A. We want to know what row, what column, and what box the index lives in. Define the following methods to do this:
  14.         1. get_row method: index / 9
  15.         2. get_column method: index % 9
  16.         3. get_box method: (column/3 + row/3) * 3
  17.     B. We want to find the existing corresponding numbers, NOT "-"'s, in the row column & box of our index value
  18.         1. get_row (index / 9) && != "-" ==> [an array of values != "-" in row]
  19.         2. get_column (index % 9) && != "-" ==> [an array of values != "-" in column]
  20.         3. get_box (box index) && != "-" ==> [an array of values != "-" in box]
  21.         # Put the results of these three arrays together for next step
  22. IV. Test if We Have a Unique Solution
  23.     A. If it is unique, it will only have 1 value in the array after we grab the unique values
  24.         if ([1..9] - existing_corresp_nums.unique).length == 1
  25.             master array [current index] = ([1..9] - existing_corresp_nums.unique).first
  26. *** A while loop is necessary to keep going back through steps II. - IV. so long as there are still "-"'s present in the master array.  Recommended to use in driver code while building the program and then adding into the program at end***
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement