Skip to content

Instantly share code, notes, and snippets.

@rajivnarayana
Last active October 12, 2022 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajivnarayana/ce919777b2f73383d04de4ddd874e2bb to your computer and use it in GitHub Desktop.
Save rajivnarayana/ce919777b2f73383d04de4ddd874e2bb to your computer and use it in GitHub Desktop.
Sudoku sample question

Write a function that receives a completed Sudoku board as parameter and returns either Finished if the Sudoku is done correctly or Try again! if not.
The board received an array of 9 subarrays as a parameter. These are the board's rows.

Sudoku rules

  • There are 9 rows in a traditional Sudoku puzzle. There may not be any duplicate numbers in any row. Each row must be unique.
  • The are 9 columns in a traditional Sudoku puzzle. There may not be any duplicate numbers in any column. Each column must be unique.
  • A region is a 3x3 box. There are 9 regions in a traditional Sudoku puzzle. There may not be any duplicate numbers in any region. Each region must be unique.
  • Every row, column and region contains the numbers one through nine only once.

Valid board example:

Example of function usage:

doneOrNot([[5, 3, 4, 6, 7, 8, 9, 1, 2],
          [6, 7, 2, 1, 9, 5, 3, 4, 8],
          [1, 9, 8, 3, 4, 2, 5, 6, 7],
          [8, 5, 9, 7, 6, 1, 4, 2, 3],
          [4, 2, 6, 8, 5, 3, 7, 9, 1],
          [7, 1, 3, 9, 2, 4, 8, 5, 6],
          [9, 6, 1, 5, 3, 7, 2, 8, 4],
          [2, 8, 7, 4, 1, 9, 6, 3, 5],
          [3, 4, 5, 2, 8, 6, 1, 7, 9]]) // "Finished!"

doneOrNot([[5, 3, 4, 6, 7, 8, 9, 1, 2],
          [6, 7, 2, 1, 9, 0, 3, 4, 9],
          [1, 0, 0, 3, 4, 2, 5, 6, 0],
          [8, 5, 9, 7, 6, 1, 0, 2, 0],
          [4, 2, 6, 8, 5, 3, 7, 9, 1],
          [7, 1, 3, 9, 2, 4, 8, 5, 6],
          [9, 0, 1, 5, 3, 7, 2, 1, 4],
          [2, 8, 7, 4, 1, 9, 6, 3, 5],
          [3, 0, 0, 4, 8, 1, 1, 7, 9]]) // "Try again!"

Solution

export function doneOrNot( board ) {
   //Insert your code here 
}
@shaik466
Copy link

Code for this question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment