From 211bb2c23f18b1e84b2f365ef455d986987f65f0 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 16 Apr 2021 16:57:39 -0700 Subject: [PATCH] Added sudoku challenge --- DIRECTORY.md | 1 + data_structures/arrays/sudoku.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 data_structures/arrays/sudoku.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..00ba121 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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 diff --git a/data_structures/arrays/sudoku.rb b/data_structures/arrays/sudoku.rb new file mode 100644 index 0000000..cae5d60 --- /dev/null +++ b/data_structures/arrays/sudoku.rb @@ -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 \ No newline at end of file