Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created March 31, 2013 05:20
Show Gist options
  • Save Stephenitis/5279633 to your computer and use it in GitHub Desktop.
Save Stephenitis/5279633 to your computer and use it in GitHub Desktop.
working at setting up and transposing a sudoku board from the rows to the column format. pay attention to the letters and numbers in the transposed array
class SudokuBoard
attr_reader :rowdata, :columns
attr_writer :rowdata, :columns
def initialize(rowdata)
@rowdata = rowdata
@columns = create_columns
end
def create_columns
@columns = @rowdata.transpose
end
end
#test case
test = SudokuBoard.new(
[["A", "1", "1", "1", "1", "1", "B", "1", "1"],
["2", "C", "2", "2", "2", "2", "2", "2", "2"],
["3", "3", "3", "D", "3", "3", "3", "3", "3"],
["4", "4", "4", "4", "4", "4", "4", "4", "4"],
["5", "5", "5", "5", "5", "5", "5", "5", "5"],
["6", "6", "6", "6", "6", "6", "6", "6", "6"],
["7", "7", "7", "7", "7", "7", "7", "7", "7"],
["8", "8", "8", "8", "8", "8", "8", "8", "8"],
["9", "9", "9", "9", "9", "9", "9", "9", "9"]])
test.columns
# =>
# ["A", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "C", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "D", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["B", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
# ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
# pay attention to the letters and numbers in the transposed array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment