5 kyu

Tic-Tac-Toe Checker

11,249 of 26,190eugene-bulkin

Description:

If we were to set up a Tic-Tac-Toe game, we would want to know whether the board's current state is solved, wouldn't we? Our goal is to create a function that will check that for us!

Assume that the board comes in the form of a 3x3 array, where the value is 0 if a spot is empty, 1 if it is an "X", or 2 if it is an "O", like so:

[[0, 0, 1],
 [0, 1, 2],
 [2, 1, 0]]

We want our function to return:

  • -1 if the board is not yet finished AND no one has won yet (there are empty spots),
  • 1 if "X" won,
  • 2 if "O" won,
  • 0 if it's a cat's game (i.e. a draw).

You may assume that the board passed in is valid in the context of a game of Tic-Tac-Toe.

Arrays
Algorithms

Stats:

CreatedOct 15, 2013
PublishedOct 15, 2013
Warriors Trained64248
Total Skips10693
Total Code Submissions177478
Total Times Completed26190
JavaScript Completions7896
CoffeeScript Completions71
Python Completions11249
C# Completions2798
PHP Completions1103
Solidity Completions165
Ruby Completions473
Go Completions531
Rust Completions425
Java Completions1414
COBOL Completions9
C Completions404
Haskell Completions31
Total Stars1352
% of votes with a positive feedback rating89% of 2283
Total "Very Satisfied" Votes1858
Total "Somewhat Satisfied" Votes365
Total "Not Satisfied" Votes60
Ad
Contributors
  • eugene-bulkin Avatar
  • dnolan Avatar
  • Unnamed Avatar
  • anter69 Avatar
  • brunolm Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • Firefly2002 Avatar
  • bshore Avatar
  • Madjosz Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • markus.benko Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • WestwardLand968 Avatar
  • akar-0 Avatar
  • tobeannouncd Avatar
  • saudiGuy Avatar
Ad