W
W
WarriorKodeK2018-02-21 11:36:06
JavaScript
WarriorKodeK, 2018-02-21 11:36:06

Algorithm to check matrix elements?

Guys, tell me how to implement an algorithm for checking all elements for the presence of "X" or "O" (that is, the entire line (the column must be filled with "X" or "O")) according to:
Horizontals - https://prnt.sc/ihp470 , that is, you need to go through all the row's.
Verticals - https://prnt.sc/ihp517 , that is, you need to go through all column's.
Diagonals (+ - I understand how to do it).
Let's say the matrix is:

[
  ["X","O","X","X","X"],
  ["X","O","X","X","X"],  
  ["X","O","X","X","X"],
  ["X","O","X","X","X"],
  ["X","O","X","X","X"]
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kulaeff, 2018-02-21
@WarriorKodeK

In general, to solve this problem, we need two functions: a function that checks if all elements of the string match the value (function 1) and a function that rotates the array by 90 degrees (function 2).
Thus, to check if at least one row of the matrix consists of X elements, you need to use function 1. To check if at least one column consists of X elements, you must first rotate the array using function 2, then use function 1.
Example solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question