Skip to content
🤔prompts chat🧠
🔍
question:from typing import List def check_tic_tac_toe_status(board: List[List[str]]) -> str: Determine the status of a tic-tac-toe game given a 3x3 matrix representing the board. Return "X" if "X" has won, "O" if "O" has won, "Draw" if the game is a draw, "Incomplete" if the game is still in progress. >>> check_tic_tac_toe_status([["X", "X", "X"], ["O", "O", ""], ["", "", "O"]]) == "X" >>> check_tic_tac_toe_status([["O", "X", "X"], ["O", "", "X"], ["O", "", ""]]) == "O" >>> check_tic_tac_toe_status([["X", "O", "O"], ["", "X", "O"], ["", "", "X"]]) == "X" >>> check_tic_tac_toe_status([["X", "X", "O"], ["X", "O", ""], ["O", "", ""]]) == "O" >>> check_tic_tac_toe_status([["X", "O", "X"], ["O", "", "O"], ["X", "O", ""]]) == "Incomplete" >>> check_tic_tac_toe_status([["X", "O", "X"], ["O", "X", "O"], ["O", "X", "O"]]) == "Draw"

answer:from typing import List def check_tic_tac_toe_status(board: List[List[str]]) -> str: # Check for win in the rows for row in board: if row[0] == row[1] == row[2] and row[0] != "": return row[0] # Check for win in the columns for col in range(3): if board[0][col] == board[1][col] == board[2][col] and board[0][col] != "": return board[0][col] # Check for win in the diagonals if board[0][0] == board[1][1] == board[2][2] and board[0][0] != "": return board[0][0] if board[0][2] == board[1][1] == board[2][0] and board[0][2] != "": return board[0][2] # Check if the game is still incomplete for row in board: if "" in row: return "Incomplete" # If none of the above, the game is a draw return "Draw" # Example usage: # board = [["X", "O", "X"], # ["O", "X", "O"], # ["O", "", "X"]] # print(check_tic_tac_toe_status(board)) # Output: "X"

question:def no_adjacent_plants(n: int, m: int, grid: List[str]) -> str: Check if no two plants are adjacent in the garden grid. Parameters: n (int): The number of rows in the grid. m (int): The number of columns in the grid. grid (list of str): The grid represented as a list of strings. Returns: str: "YES" if no two plants are adjacent, "NO" otherwise. # Your implementation here # Unit tests def test_no_adjacent_plants(): n, m = 3, 3 grid = ['101', '010', '101'] assert no_adjacent_plants(n, m, grid) == "YES" n, m = 3, 3 grid = ['110', '000', '101'] assert no_adjacent_plants(n, m, grid) == "NO" n, m = 1, 5 grid = ['10001'] assert no_adjacent_plants(n, m, grid) == "YES" n, m = 5, 1 grid = ['1', '0', '0', '1', '0'] assert no_adjacent_plants(n, m, grid) == "YES" n, m = 4, 4 grid = ['1001', '0000', '1001', '0000'] assert no_adjacent_plants(n, m, grid) == "YES" n, m = 4, 4 grid = ['1001', '0110', '1001', '0000'] assert no_adjacent_plants(n, m, grid) == "NO" n, m = 3, 3 grid = ['000', '000', '000'] assert no_adjacent_plants(n, m, grid) == "YES" n, m = 2, 2 grid = ['11', '11'] assert no_adjacent_plants(n, m, grid) == "NO"

answer:def no_adjacent_plants(n, m, grid): Check if no two plants are adjacent in the garden grid. Parameters: n (int): The number of rows in the grid. m (int): The number of columns in the grid. grid (list of str): The grid represented as a list of strings. Returns: str: "YES" if no two plants are adjacent, "NO" otherwise. for i in range(n): for j in range(m): if grid[i][j] == '1': if (i > 0 and grid[i - 1][j] == '1') or (i < n - 1 and grid[i + 1][j] == '1') or (j > 0 and grid[i][j - 1] == '1') or (j < m - 1 and grid[i][j + 1] == '1'): return "NO" return "YES"

question:def extract_and_sort_digits(input_str: str) -> str: Extracts all digits from the input string, sorts them in ascending order, and returns the sorted digits as a string. If there are no digits, returns an empty string. >>> extract_and_sort_digits("a1b2c3") == "123" >>> extract_and_sort_digits("abc") == "" >>> extract_and_sort_digits("64a3c9b2") == "23469"

answer:def extract_and_sort_digits(input_str): Extracts all digits from the input string, sorts them in ascending order, and returns the sorted digits as a string. If there are no digits, returns an empty string. digits = [char for char in input_str if char.isdigit()] sorted_digits = ''.join(sorted(digits)) return sorted_digits

question:def is_toeplitz(matrix: List[List[int]]) -> str: Determine if the given matrix is a Toeplitz matrix. In a Toeplitz matrix, every diagonal from top-left to bottom-right has the same elements. Args: matrix (List[List[int]]): A 2D list representing the matrix Returns: str: "YES" if the matrix is a Toeplitz matrix, "NO" otherwise. Examples: >>> is_toeplitz([ ... [1, 2, 3], ... [4, 1, 2], ... [5, 4, 1] ... ]) 'YES' >>> is_toeplitz([ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9] ... ]) 'NO'

answer:def is_toeplitz(matrix): Returns "YES" if the matrix is a Toeplitz matrix, and "NO" otherwise. n = len(matrix) for i in range(n): for j in range(n): if i > 0 and j > 0 and matrix[i][j] != matrix[i-1][j-1]: return "NO" return "YES"

Released under the chat License.

has loaded