Skip to content

Instantly share code, notes, and snippets.

@thatPamIAm
Created October 29, 2019 18:32
Show Gist options
  • Save thatPamIAm/2db71c3e114d2b93c2d328f268311678 to your computer and use it in GitHub Desktop.
Save thatPamIAm/2db71c3e114d2b93c2d328f268311678 to your computer and use it in GitHub Desktop.
Write a program that checks if a Sudoku board is completed correctly.
var input = [
  [4, 3, 5], [2, 6, 9], [7, 8, 1],
  [6, 8, 2], [5, 7, 1], [4, 9, 3],
  [1, 9, 7], [8, 3, 4], [5, 6, 2],
  [8, 2, 6], [1, 9, 5], [3, 4, 7],
  [3, 7, 4], [6, 8, 2], [9, 1, 5],
  [9, 5, 1], [7, 4, 3], [6, 2, 8],
  [5, 1, 9], [3, 2, 6], [8, 7, 4],
  [2, 4, 8], [9, 5, 7], [1, 3, 6],
  [7, 6, 3], [4, 1, 8], [2, 5, 9]
]

isVaildSudoku(input); #=> true

var input = [
  [4, 3, 5], [2, 6, 9], [7, 8, 1],
  [6, 8, 2], [5, 7, 1], [4, 9, 3],
  [1, 9, 7], [8, 3, 4], [5, 6, 2],
  [8, 2, 6], [1, 9, 5], [3, 4, 7],
  [3, 7, 4], [6, 8, 7], [9, 1, 5],
  [9, 5, 1], [7, 4, 3], [6, 2, 8],
  [5, 1, 9], [3, 2, 6], [8, 7, 4],
  [2, 4, 8], [9, 5, 7], [1, 3, 6],
  [7, 6, 3], [4, 1, 8], [2, 5, 9]
]

isVaildSudoku(input); #=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment