Skip to main content

Word Search Puzzle Generator

Introduction

The mission of this package is to generate a word search puzzle. The requirements are a list of the word and the dimensions of the puzzle.

For example:

  • Given list of words ['Cat', 'Bear', 'Tiger', 'Lion']
  • Generated panel:
#   _________________________
#  | [L]   w    m    e   [r] |
#  | [i]   w   [C]  [e]   x  |
#  | [o]   v   [g]  [a]   q  |
#  | [n]  [i]   n    i   [t] |
#  | [T]  [B]  [e]  [a]  [r] |
#   -------------------------


panel.cells = {
    (0, 0): 'l', (0, 1): 'w', (0, 2): 'm', (0, 3): 'e', (0, 4): 'r', 
    (1, 0): 'i', (1, 1): 'w', (1, 2): 'c', (1, 3): 'e', (1, 4): 'x', 
    (2, 0): 'o', (2, 1): 'v', (2, 2): 'g', (2, 3): 'a', (2, 4): 'q', 
    (3, 0): 'n', (3, 1): 'i', (3, 2): 'n', (3, 3): 'i', (3, 4): 't', 
    (4, 0): 't', (4, 1): 'b', (4, 2): 'e', (4, 3): 'a', (4, 4): 'r', 
}
  • With the corresponding hidden words:
{
    "words": [
        {
            "value": "cat",
            "positions": [
                { "r": 1, "c": 2 },
                { "r": 2, "c": 3 },
                { "r": 3, "c": 4 }
            ]
        },
        {
            "value": "bear",
            "positions": [
                { "r": 4, "c": 1 },
                { "r": 4, "c": 2 },
                { "r": 4, "c": 3 },
                { "r": 4, "c": 4 }
            ]
        },
        {
            "value": "tiger",
            "positions": [
                { "r": 4, "c": 0 },
                { "r": 3, "c": 1 },
                { "r": 2, "c": 2 },
                { "r": 1, "c": 3 },
                { "r": 0, "c": 4 }
            ]
        },
        {
            "value": "lion",
            "positions": [
                { "r": 0, "c": 0 },
                { "r": 1, "c": 0 },
                { "r": 2, "c": 0 },
                { "r": 3, "c": 0 }
            ]
        }
    ]
}

Install

You can install it using pip tool word-search-puzzle.

Generate a puzzle

All what you need is de define a list of words and provide the dimensions of the panel. Please make sure that the number and the length of the words fit the dimensions of the panel.

Example 1

Creating a simple puzzle.

from word_search_puzzle.utils import display_panel
from word_search_puzzle.algorithms import create_panel

words = ['Cat', 'Bear', 'Tiger', 'Lion']

result = create_panel(height=5, width=5, words_value_list=words)

print('Attempts: {}'.format(result.get('attempts')))
print('Solution took: {} ms'.format(result.get('elapsed_time')))
display_panel(result.get('panel'))

# Output:
#   Attempts: 2
#   Solution took: 31 ms
#
#   l  w  m  e  r
#   i  w  c  e  x
#   o  v  g  a  q
#   n  i  n  i  t
#   t  b  e  a  r

Example 2

Creating a serializable puzzle.

import json
from word_search_puzzle.algorithms import create_panel

words = ['Cat', 'Bear', 'Tiger', 'Lion']

result = create_panel(height=5, width=5, words_value_list=words, as_dict=True)

print(json.dumps(result))

The output will be as following:

{
  "panel": {
    "cells": [
      {
        "position": {
          "r": 0,
          "c": 0
        },
        "value": "t"
      },
      {
        "position": {
          "r": 0,
          "c": 1
        },
        "value": "b"
      },
      {
        "position": {
          "r": 0,
          "c": 2
        },
        "value": "x"
      },
      {
        "position": {
          "r": 0,
          "c": 3
        },
        "value": "j"
      },
      {
        "position": {
          "r": 0,
          "c": 4
        },
        "value": "c"
      },
      {
        "position": {
          "r": 1,
          "c": 0
        },
        "value": "l"
      },
      {
        "position": {
          "r": 1,
          "c": 1
        },
        "value": "i"
      },
      {
        "position": {
          "r": 1,
          "c": 2
        },
        "value": "e"
      },
      {
        "position": {
          "r": 1,
          "c": 3
        },
        "value": "b"
      },
      {
        "position": {
          "r": 1,
          "c": 4
        },
        "value": "a"
      },
      {
        "position": {
          "r": 2,
          "c": 0
        },
        "value": "c"
      },
      {
        "position": {
          "r": 2,
          "c": 1
        },
        "value": "i"
      },
      {
        "position": {
          "r": 2,
          "c": 2
        },
        "value": "g"
      },
      {
        "position": {
          "r": 2,
          "c": 3
        },
        "value": "a"
      },
      {
        "position": {
          "r": 2,
          "c": 4
        },
        "value": "t"
      },
      {
        "position": {
          "r": 3,
          "c": 0
        },
        "value": "d"
      },
      {
        "position": {
          "r": 3,
          "c": 1
        },
        "value": "l"
      },
      {
        "position": {
          "r": 3,
          "c": 2
        },
        "value": "o"
      },
      {
        "position": {
          "r": 3,
          "c": 3
        },
        "value": "e"
      },
      {
        "position": {
          "r": 3,
          "c": 4
        },
        "value": "r"
      },
      {
        "position": {
          "r": 4,
          "c": 0
        },
        "value": "f"
      },
      {
        "position": {
          "r": 4,
          "c": 1
        },
        "value": "i"
      },
      {
        "position": {
          "r": 4,
          "c": 2
        },
        "value": "i"
      },
      {
        "position": {
          "r": 4,
          "c": 3
        },
        "value": "n"
      },
      {
        "position": {
          "r": 4,
          "c": 4
        },
        "value": "r"
      }
    ]
  },
  "words": [
    {
      "value": "tiger",
      "positions": [
        {
          "r": 0,
          "c": 0
        },
        {
          "r": 1,
          "c": 1
        },
        {
          "r": 2,
          "c": 2
        },
        {
          "r": 3,
          "c": 3
        },
        {
          "r": 4,
          "c": 4
        }
      ]
    },
    {
      "value": "lion",
      "positions": [
        {
          "r": 1,
          "c": 0
        },
        {
          "r": 2,
          "c": 1
        },
        {
          "r": 3,
          "c": 2
        },
        {
          "r": 4,
          "c": 3
        }
      ]
    },
    {
      "value": "cat",
      "positions": [
        {
          "r": 0,
          "c": 4
        },
        {
          "r": 1,
          "c": 4
        },
        {
          "r": 2,
          "c": 4
        }
      ]
    },
    {
      "value": "bear",
      "positions": [
        {
          "r": 0,
          "c": 1
        },
        {
          "r": 1,
          "c": 2
        },
        {
          "r": 2,
          "c": 3
        },
        {
          "r": 3,
          "c": 4
        }
      ]
    }
  ],
  "attempts": 1,
  "found": true,
  "elapsed_time": 3
}

Release files for word-search-puzzle 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for word-search-puzzle 2.0.1
File Size Uploaded
word-search-puzzle-2.0.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for word-search-puzzle 2.0.1
File Interpreter ABI Platform
word_search_puzzle-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / word-search-puzzle-2.0.1.tar.gz

Download URL word-search-puzzle-2.0.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7194bdd1da7306f87ba1d287e40905f5baa60375a33537c17554370002716b74
BLAKE2b-256 checksum
How to use checksums
b31ebbd039ec04ac51479afb9400536b269607e2acf0960051f327114a3e3cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1

Release files / word_search_puzzle-2.0.1-py3-none-any.whl

Download URL word_search_puzzle-2.0.1-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2b3eadf095ee9616f67afd6ab40ce1d683ca1efec592ec30647d354bcc58695
BLAKE2b-256 checksum
How to use checksums
12c1becaccec2adb840971b851e57f611987386db951fea244bbfa57ad36e867
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0

3 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.6

2 release files

0.4

2 release files

0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page