backtracking.crossword_puzzle_solver ==================================== .. py:module:: backtracking.crossword_puzzle_solver Attributes ---------- .. autoapisummary:: backtracking.crossword_puzzle_solver.PUZZLE Functions --------- .. autoapisummary:: backtracking.crossword_puzzle_solver.is_valid backtracking.crossword_puzzle_solver.place_word backtracking.crossword_puzzle_solver.remove_word backtracking.crossword_puzzle_solver.solve_crossword Module Contents --------------- .. py:function:: is_valid(puzzle: list[list[str]], word: str, row: int, col: int, vertical: bool) -> bool Check if a word can be placed at the given position. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> is_valid(puzzle, 'word', 0, 0, True) True >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> is_valid(puzzle, 'word', 0, 0, False) True .. py:function:: place_word(puzzle: list[list[str]], word: str, row: int, col: int, vertical: bool) -> None Place a word at the given position. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> place_word(puzzle, 'word', 0, 0, True) >>> puzzle [['w', '', '', ''], ['o', '', '', ''], ['r', '', '', ''], ['d', '', '', '']] .. py:function:: remove_word(puzzle: list[list[str]], word: str, row: int, col: int, vertical: bool) -> None Remove a word from the given position. >>> puzzle = [ ... ['w', '', '', ''], ... ['o', '', '', ''], ... ['r', '', '', ''], ... ['d', '', '', ''] ... ] >>> remove_word(puzzle, 'word', 0, 0, True) >>> puzzle [['', '', '', ''], ['', '', '', ''], ['', '', '', ''], ['', '', '', '']] .. py:function:: solve_crossword(puzzle: list[list[str]], words: list[str]) -> bool Solve the crossword puzzle using backtracking. >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> words = ['word', 'four', 'more', 'last'] >>> solve_crossword(puzzle, words) True >>> puzzle = [ ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''], ... ['', '', '', ''] ... ] >>> words = ['word', 'four', 'more', 'paragraphs'] >>> solve_crossword(puzzle, words) False .. py:data:: PUZZLE