Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. Sudoku is a number-placement puzzle. The objective is to fill a 9 × 9 grid with numbers in such a way that each column, each row, and each of the nine 3 × 3 sub-grids that compose the grid all contain all of the numbers from 1 to 9 one time.
  2.  
  3. Implement an algorithm that will check whether the given grid of numbers represents a valid Sudoku puzzle according to the layout rules described above. Note that the puzzle represented by grid does not have to be solvable.
  4.  
  5. Example
  6.  
  7. For
  8.  
  9. grid = [['.', '.', '.', '1', '4', '.', '.', '2', '.'],
  10. ['.', '.', '6', '.', '.', '.', '.', '.', '.'],
  11. ['.', '.', '.', '.', '.', '.', '.', '.', '.'],
  12. ['.', '.', '1', '.', '.', '.', '.', '.', '.'],
  13. ['.', '6', '7', '.', '.', '.', '.', '.', '9'],
  14. ['.', '.', '.', '.', '.', '.', '8', '1', '.'],
  15. ['.', '3', '.', '.', '.', '.', '.', '.', '6'],
  16. ['.', '.', '.', '.', '.', '7', '.', '.', '.'],
  17. ['.', '.', '.', '5', '.', '.', '.', '7', '.']]
  18. the output should be
  19. sudoku2(grid) = true;
  20.  
  21. For
  22.  
  23. grid = [['.', '.', '.', '.', '2', '.', '.', '9', '.'],
  24. ['.', '.', '.', '.', '6', '.', '.', '.', '.'],
  25. ['7', '1', '.', '.', '7', '5', '.', '.', '.'],
  26. ['.', '7', '.', '.', '.', '.', '.', '.', '.'],
  27. ['.', '.', '.', '.', '8', '3', '.', '.', '.'],
  28. ['.', '.', '8', '.', '.', '7', '.', '6', '.'],
  29. ['.', '.', '.', '.', '.', '2', '.', '.', '.'],
  30. ['.', '1', '.', '2', '.', '.', '.', '.', '.'],
  31. ['.', '2', '.', '.', '3', '.', '.', '.', '.']]
  32. the output should be
  33. sudoku2(grid) = false.
  34.  
  35. The given grid is not correct because there are two 1s in the second column. Each column, each row, and each 3 × 3 subgrid can only contain the numbers 1 through 9 one time.
  36.  
  37. Input/Output
  38.  
  39. [execution time limit] 4 seconds (js)
  40.  
  41. [input] array.array.char grid
  42.  
  43. A 9 × 9 array of characters, in which each character is either a digit from '1' to '9' or a period '.'.
  44.  
  45. [output] boolean
  46.  
  47. Return true if grid represents a valid Sudoku puzzle, otherwise return false.
  48. [JavaScript (ES6)] Syntax Tips
  49.  
  50. // Prints help message to the console
  51. // Returns a string
  52. function helloWorld(name) {
  53. console.log("This prints to the console when you Run Tests");
  54. return "Hello, " + name;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement