other.word_search¶

Creates a random wordsearch with eight different directions that are best described as compass locations.

@ https://en.wikipedia.org/wiki/Word_search

Attributes¶

HEIGHT

WIDTH

WORDS

Classes¶

WordSearch

Functions¶

visualise_word_search(→ None)

Graphically displays the word search in the terminal.

Module Contents¶

class other.word_search.WordSearch(words: list[str], width: int, height: int)¶
>>> ws = WordSearch(WORDS, WIDTH, HEIGHT)
>>> ws.board  
[[None, ..., None], ..., [None, ..., None]]
>>> ws.generate_board()
generate_board() → None¶

Generates a board with a random direction for each word.

>>> wt = WordSearch(WORDS, WIDTH, HEIGHT)
>>> wt.generate_board()
>>> len(list(filter(lambda word: word is not None, sum(wt.board, start=[])))
... ) == sum(map(lambda word: len(word), WORDS))
True
insert_east(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_east("cat", [1], [0])
>>> ws.board  
[[None, None, None],
['c', 'a', 't'],
[None, None, None]]
>>> ws.insert_east("at", [1, 0], [2, 1, 0])
>>> ws.board  
[[None, 'a', 't'],
['c', 'a', 't'],
[None, None, None]]
insert_north(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_north("cat", [2], [2])
>>> ws.board  
[[None, None, 't'],
[None, None, 'a'],
[None, None, 'c']]
>>> ws.insert_north("at", [0, 1, 2], [2, 1])
>>> ws.board  
[[None, 't', 't'],
[None, 'a', 'a'],
[None, None, 'c']]
insert_northeast(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_northeast("cat", [2], [0])
>>> ws.board  
[[None, None, 't'],
[None, 'a', None],
['c', None, None]]
>>> ws.insert_northeast("at", [0, 1], [2, 1, 0])
>>> ws.board  
[[None, 't', 't'],
['a', 'a', None],
['c', None, None]]
insert_northwest(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_northwest("cat", [2], [2])
>>> ws.board  
[['t', None, None],
[None, 'a', None],
[None, None, 'c']]
>>> ws.insert_northwest("at", [1, 2], [0, 1])
>>> ws.board  
[['t', None, None],
['t', 'a', None],
[None, 'a', 'c']]
insert_south(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_south("cat", [0], [0])
>>> ws.board  
[['c', None, None],
['a', None, None],
['t', None, None]]
>>> ws.insert_south("at", [2, 1, 0], [0, 1, 2])
>>> ws.board  
[['c', None, None],
['a', 'a', None],
['t', 't', None]]
insert_southeast(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_southeast("cat", [0], [0])
>>> ws.board  
[['c', None, None],
[None, 'a', None],
[None, None, 't']]
>>> ws.insert_southeast("at", [1, 0], [2, 1, 0])
>>> ws.board  
[['c', None, None],
['a', 'a', None],
[None, 't', 't']]
insert_southwest(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_southwest("cat", [0], [2])
>>> ws.board  
[[None, None, 'c'],
[None, 'a', None],
['t', None, None]]
>>> ws.insert_southwest("at", [1, 2], [2, 1, 0])
>>> ws.board  
[[None, None, 'c'],
[None, 'a', 'a'],
['t', 't', None]]
insert_west(word: str, rows: list[int], cols: list[int]) → None¶
>>> ws = WordSearch(WORDS, 3, 3)
>>> ws.insert_west("cat", [1], [2])
>>> ws.board  
[[None, None, None],
['t', 'a', 'c'],
[None, None, None]]
>>> ws.insert_west("at", [1, 0], [1, 2, 0])
>>> ws.board  
[['t', 'a', None],
['t', 'a', 'c'],
[None, None, None]]
board: list[list[str | None]]¶
height¶
width¶
words¶
other.word_search.visualise_word_search(board: list[list[str | None]] | None = None, *, add_fake_chars: bool = True) → None¶

Graphically displays the word search in the terminal.

>>> ws = WordSearch(WORDS, 5, 5)
>>> ws.insert_north("cat", [4], [4])
>>> visualise_word_search(
...     ws.board, add_fake_chars=False)  
# # # # #
# # # # #
# # # # t
# # # # a
# # # # c
>>> ws.insert_northeast("snake", [4], [4, 3, 2, 1, 0])
>>> visualise_word_search(
...     ws.board, add_fake_chars=False)  
# # # # e
# # # k #
# # a # t
# n # # a
s # # # c
other.word_search.HEIGHT = 10¶
other.word_search.WIDTH = 10¶
other.word_search.WORDS = ['cat', 'dog', 'snake', 'fish']¶

thealgorithms-python

Navigation

index.md

  • Contributing guidelines
  • Getting Started
  • Community Channels
  • List of Algorithms
  • MIT License
  • API Reference
    • maths
    • other
    • sorts
    • graphs
    • hashes
    • matrix
    • ciphers
    • geodesy
    • physics
    • quantum
    • strings
    • fractals
    • geometry
    • graphics
    • knapsack
    • searches
    • financial
    • blockchain
    • scheduling
    • compression
    • conversions
    • electronics
    • fuzzy_logic
    • backtracking
    • audio_filters
    • file_transfer
    • project_euler
    • greedy_methods
    • linear_algebra
    • neural_network
    • boolean_algebra
    • computer_vision
    • data_structures
    • networking_flow
    • web_programming
    • bit_manipulation
    • machine_learning
    • cellular_automata
    • genetic_algorithm
    • divide_and_conquer
    • linear_programming
    • dynamic_programming
    • digital_image_processing

Related Topics

  • Documentation overview
    • API Reference
      • other
        • Previous: other.tower_of_hanoi
        • Next: sorts
©2014, TheAlgorithms. | Powered by Sphinx 8.1.3 & Alabaster 1.0.0 | Page source