Untitled

 avatar
unknown
plain_text
23 days ago
2.6 kB
1
Indexable
import random

# List of names for the word search puzzle
names = [
    "Sreelatha", "Satwik", "Kavya", "Satish", "Soumya", "Vamsi", "MGouri", "DMurthy", "Venkatesh", "Jyothi",
    "Sahithi", "Suseela", "Padma", "Kishore", "Sindu", "Bhoomi", "Ashwin", "Uma", "Ramesh", "Kavitha", "Alekhya",
    "Arnith", "Hariprasad", "Ratna", "Sreenee", "Ankit", "Theia", "Sreeven", "Srinivas", "Sunitha", "Shashank",
    "Sudhamsh", "Gouri", "Suresh", "Himanshu", "Pravalika", "Devender", "Avanthi", "Sadhya", "Jashwanth", "Sravya",
    "Chintoo", "Ramamani", "Lakshmamma", "Sanjay", "Shilpa", "Vaishanavi", "Meghanansh", "Viransh", "Viyaan",
    "Savitha", "Srikar", "Vastav", "Lalit", "Bharath", "Akshay", "Alok", "Afaq", "Prasuna", "Alisha", "Caro",
    "Vasanth", "Pujitha", "Sneha", "raviteja", "mounika", "chaitanya", "harika"
]

# Grid size (adjust based on word count and length)
grid_size = 30

# Initialize an empty grid
grid = [[" " for _ in range(grid_size)] for _ in range(grid_size)]

# Directions for placing words (x, y offsets)
directions = [
    (0, 1), (1, 0), (0, -1), (-1, 0),  # Horizontal and vertical
    (1, 1), (1, -1), (-1, 1), (-1, -1) # Diagonals
]

# Function to check if a word fits in the grid at a specific position and direction
def can_place_word(word, x, y, dx, dy):
    for i in range(len(word)):
        nx, ny = x + i * dx, y + i * dy
        if not (0 <= nx < grid_size and 0 <= ny < grid_size) or (grid[nx][ny] != " " and grid[nx][ny] != word[i]):
            return False
    return True

# Function to place a word in the grid
def place_word(word, x, y, dx, dy):
    for i in range(len(word)):
        nx, ny = x + i * dx, y + i * dy
        grid[nx][ny] = word[i]

# Randomly shuffle the list of names
random.shuffle(names)

# Attempt to place each word in the grid
for word in names:
    placed = False
    attempts = 0
    while not placed and attempts < 100:  # Limit attempts to prevent infinite loops
        x, y = random.randint(0, grid_size - 1), random.randint(0, grid_size - 1)
        dx, dy = random.choice(directions)
        if can_place_word(word.upper(), x, y, dx, dy):
            place_word(word.upper(), x, y, dx, dy)
            placed = True
        attempts += 1

# Fill the empty spaces with random letters
for i in range(grid_size):
    for j in range(grid_size):
        if grid[i][j] == " ":
            grid[i][j] = random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

# Convert grid to a printable string format
puzzle = "\n".join(" ".join(row) for row in grid)

# Save the puzzle and solution
print(puzzle)
Leave a Comment