mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Added sudoku challenge
This commit is contained in:
parent
a472f9a6ff
commit
211bb2c23f
2 changed files with 41 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
* [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb)
|
||||
* [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb)
|
||||
* [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb)
|
||||
* [Sudoku](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/sudoku.rb)
|
||||
* [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb)
|
||||
* [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb)
|
||||
* Binary Trees
|
||||
|
|
40
data_structures/arrays/sudoku.rb
Normal file
40
data_structures/arrays/sudoku.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
# Challenge name: Valid Sudoku
|
||||
|
||||
# Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
|
||||
# Each row must contain the digits 1-9 without repetition.
|
||||
# Each column must contain the digits 1-9 without repetition.
|
||||
# Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
|
||||
|
||||
# @param {Character[][]} board
|
||||
# @return {Boolean}
|
||||
|
||||
#
|
||||
# Approach 1:
|
||||
#
|
||||
# Time Complexity:
|
||||
#
|
||||
def is_valid_sudoku(board)
|
||||
end
|
||||
|
||||
board = [["5","3",".",".","7",".",".",".","."]
|
||||
,["6",".",".","1","9","5",".",".","."]
|
||||
,[".","9","8",".",".",".",".","6","."]
|
||||
,["8",".",".",".","6",".",".",".","3"]
|
||||
,["4",".",".","8",".","3",".",".","1"]
|
||||
,["7",".",".",".","2",".",".",".","6"]
|
||||
,[".","6",".",".",".",".","2","8","."]
|
||||
,[".",".",".","4","1","9",".",".","5"]
|
||||
,[".",".",".",".","8",".",".","7","9"]]
|
||||
print(is_valid_sudoku(board))
|
||||
# => true
|
||||
board = [["8","3",".",".","7",".",".",".","."]
|
||||
,["6",".",".","1","9","5",".",".","."]
|
||||
,[".","9","8",".",".",".",".","6","."]
|
||||
,["8",".",".",".","6",".",".",".","3"]
|
||||
,["4",".",".","8",".","3",".",".","1"]
|
||||
,["7",".",".",".","2",".",".",".","6"]
|
||||
,[".","6",".",".",".",".","2","8","."]
|
||||
,[".",".",".","4","1","9",".",".","5"]
|
||||
,[".",".",".",".","8",".",".","7","9"]]
|
||||
print(is_valid_sudoku(board))
|
||||
# => false
|
Loading…
Reference in a new issue