Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sudoku Pseudocode:
- I. Create Board
- A. Split the input string
- string.split("")
- B. Convert into an array
- [master array]
- II. Find empty cell
- A. Find first "-" in master array
- B. Define the variable
- current index = index # this is our unique id number!
- III. Collect Corresponding Filled Cells
- A. We want to know what row, what column, and what box the index lives in. Define the following methods to do this:
- 1. get_row method: index / 9
- 2. get_column method: index % 9
- 3. get_box method: (column/3 + row/3) * 3
- B. We want to find the existing corresponding numbers, NOT "-"'s, in the row column & box of our index value
- 1. get_row (index / 9) && != "-" ==> [an array of values != "-" in row]
- 2. get_column (index % 9) && != "-" ==> [an array of values != "-" in column]
- 3. get_box (box index) && != "-" ==> [an array of values != "-" in box]
- # Put the results of these three arrays together for next step
- IV. Test if We Have a Unique Solution
- A. If it is unique, it will only have 1 value in the array after we grab the unique values
- if ([1..9] - existing_corresp_nums.unique).length == 1
- master array [current index] = ([1..9] - existing_corresp_nums.unique).first
- *** 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