>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_east("cat", [1], [0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, None], ['c', 'a', 't'], [None, None, None]] >>> ws.insert_east("at", [1, 0], [2, 1, 0]) >>> ws.board # d
(self, word: str, rows: list[int], cols: list[int])
| 104 | return |
| 105 | |
| 106 | def insert_east(self, word: str, rows: list[int], cols: list[int]) -> None: |
| 107 | """ |
| 108 | >>> ws = WordSearch(WORDS, 3, 3) |
| 109 | >>> ws.insert_east("cat", [1], [0]) |
| 110 | >>> ws.board # doctest: +NORMALIZE_WHITESPACE |
| 111 | [[None, None, None], |
| 112 | ['c', 'a', 't'], |
| 113 | [None, None, None]] |
| 114 | >>> ws.insert_east("at", [1, 0], [2, 1, 0]) |
| 115 | >>> ws.board # doctest: +NORMALIZE_WHITESPACE |
| 116 | [[None, 'a', 't'], |
| 117 | ['c', 'a', 't'], |
| 118 | [None, None, None]] |
| 119 | """ |
| 120 | word_length = len(word) |
| 121 | # Attempt to insert the word into each row and when successful, exit |
| 122 | for row in rows: |
| 123 | # Attempt to insert the word into each column |
| 124 | for col in cols: |
| 125 | # Check if there is space to the right of the word |
| 126 | if word_length + col > self.width: |
| 127 | continue |
| 128 | |
| 129 | # Check if there are existing letters |
| 130 | # to the right of the column that will be overwritten |
| 131 | letters_left = [self.board[row][col + i] for i in range(word_length)] |
| 132 | if all(letter is None for letter in letters_left): |
| 133 | # Successful, insert the word east |
| 134 | for i in range(word_length): |
| 135 | self.board[row][col + i] = word[i] |
| 136 | return |
| 137 | |
| 138 | def insert_southeast(self, word: str, rows: list[int], cols: list[int]) -> None: |
| 139 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected