
    gu                     F    d dl Z d Zd Zd ZddZd Zedk(  r e        yy)	    Nc                 H    t        j                  dd      dk(  r| d d d   S | S )N      )randomrandint)words    I/var/www/openai/venv/lib/python3.12/site-packages/nltk/misc/wordfinder.pyrevwordr      s(    ~~aq DbDzK    c                     t        t        |             D ]6  }| ||          ||         dk7  s| ||          ||         | |   k7  s6 y t        t        |             D ]  }| |   | ||          ||      <    y)N FT)rangelen)r	   xxfyyfgridis          r
   stepr      s    3t91;r!u#RUBqE(:d1g(E  3t9!!WRUBqE r   c                    |dk(  r9t        |       z
  dk  st        |       z
  dk  ryt        | fdfd|      S |dk(  r(t        |       z
  dk  ryt        | fdfd|      S |d	k(  r<t        |       z
  dk  st        |       dz
  z   |k\  ryt        | fd
fd|      S |dk(  r(t        |       z
  dk  ryt        | fdfd|      S y )Nr   r   Fc                     | z
  S N r   r   s    r
   <lambda>zcheck.<locals>.<lambda>$   	    q1ur   c                     | z
  S r   r   r   r   s    r
   r   zcheck.<locals>.<lambda>$   	    1q5r   r   c                     | z
  S r   r   r   s    r
   r   zcheck.<locals>.<lambda>(   r   r   c                     S r   r   r    s    r
   r   zcheck.<locals>.<lambda>(   s    1r      c                     | z
  S r   r   r   s    r
   r   zcheck.<locals>.<lambda>,   r   r   c                     | z   S r   r   r    s    r
   r   zcheck.<locals>.<lambda>,   r!   r      c                     S r   r   r   s    r
   r   zcheck.<locals>.<lambda>0   s    qr   c                     | z
  S r   r   r    s    r
   r   zcheck.<locals>.<lambda>0   s	    q1ur   )r   r   )r	   dirr   r   r   rowscolss     ``   r
   checkr-       s    
axs4y=1CI 1D!_a$GG	s4y=1D!_adCC	s4y=1SY] 3t ;D!_a$GG	s4y=1D![!_dCC 
r   c                 J   t        | t        d      } g }g }t        |      D ]  }|j                  dg|z          | D ]  }|j	                         j                         }|}	t        |      }t        |      D ]  }
t        j                  dt        |            }t        j                  g d      }t        j                  d|      }t        j                  d|      }|dk(  r||z  }||z  }n%|dk(  r||z  }n|dk(  r||z  }||z  }n
|d	k(  r||z  }d|cxk  r|k  sn d|cxk  r|k  sn t        |||||||      s|j                  |	          t        |      D ]9  }t        |      D ])  }||   |   dk(  st        j                  |      ||   |<   + ; ||fS )
a  
    Attempt to arrange words into a letter-grid with the specified
    number of rows and columns.  Try each word in several positions
    and directions, until it can be fitted into the grid, or the
    maximum number of allowable attempts is exceeded.  Returns a tuple
    consisting of the grid and the words that were successfully
    placed.

    :param words: the list of words to be put into the grid
    :type words: list
    :param rows: the number of rows in the grid
    :type rows: int
    :param cols: the number of columns in the grid
    :type cols: int
    :param attempts: the number of times to attempt placing a word
    :type attempts: int
    :param alph: the alphabet, to be used for filling blank cells
    :type alph: list
    :rtype: tuple
    T)keyreverser   r   )r   r   r$   r'   r   r   r$   r'   )sortedr   r   appendstripupperr   r   r   choicer-   )wordsr+   r,   attemptsalphr   usedr   r	   saveattemptrr*   r   r   js                   r
   
wordfinderr>   3   s   . 5c40EDD 4[RD4K   zz|!!#t}XGq#d),A---Cq$'Aq$'AaxQQQQQQA}}a$sAq$d;KK%' '	 4 4[tAAwqzR#]]40Q
  
 :r   c                     ddl m}  | j                         }t        j                  |       |d d }|D cg c]  }dt	        |      cxk  rdk  sn n| }}t        |      \  }}t        d       t        t	        |            D ];  }t        t	        ||               D ]  }t        ||   |   d        t                = t                t        t	        |            D ]  }t        d	|d
z   z  ||           y c c}w )Nr   )r6      r$      zWord Finder
 )endz%d:r   )nltk.corpusr6   r   shuffler   r>   printr   )r6   wordlistwr   r9   r   r=   s          r
   word_finderrI   v   s    !{{}H
NN8~H#98aqCF'8b'88H9H%JD$	/3t9s47|$A$q'!*#& %  
G3t9eq1uotAw'  :s   C<C<__main__)   rK   2   ABCDEFGHIJKLMNOPQRSTUVWXYZ)r   r   r   r-   r>   rI   __name__r   r   r
   <module>rO      s:    D&@F(( zM r   