JL iuFddlZdZdZdZddZdZedk(reyy) NcHtjdddk(r|dddS|S)N)randomrandint)words Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/misc/wordfinder.pyrevwordr s( ~~aq DbDz Kctt|D]6}|||||dk7s|||||||k7s6ytt|D]}|||||||<y)NFT)rangelen)r xxfyyfgridis r steprs 3t9  1;r!u  #RU BqE(:d1g(E3t9 %!!WRU BqE% r c|dk(r9t|z dkst|z dkryt|fdfd|S|dk(r(t|z dkryt|fdfd|S|d k(r<t|z dkst|dz z|k\ryt|fd fd |S|d k(r(t|z dkryt|fd fd|Sy)NrrFc|z SNrrs r zcheck..$ q1ur c|z Srrrrs r rzcheck..$ 1q5r rc|z Srrrs r rzcheck..(rr cSrrr s r rzcheck..(s1r c|z Srrrs r rzcheck..,rr c|zSrrr s r rzcheck..,r!r cSrrrs r rzcheck..0sqr c|z Srrr s r rzcheck..0s q1ur )rr)r dirrrrrowscolss `` r checkr- s ax s4y=1 CI  1D!_a$GG  s4y=1 D!_adCC  s4y=1 SY] 3t ;D!_a$GG  s4y=1 D![!_dCC r c Jt|td}g}g}t|D]}|jdg|z|D]}|j j }|} t |}t|D]} tjdt|} tjgd} tjd|} tjd|}| dk(r | | z } || z }n%| dk(r| | z } n| dk(r | | z } || z}n | d k(r|| z }d| cxkr|ksnd|cxkr|ksnt|| | ||||s|j| t|D]9}t|D])}|||dk(stj||||<+;||fS) 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)keyreverserr)rrr$r'rrr$r') sortedrrappendstripupperr rrchoicer-)wordsr+r,attemptsalphrusedrr saveattemptrr*rrjs r wordfinderr>3s. 5c4 0E D D4[! RD4K !zz|!!#t}X Gq#d),A-- -Cq$'Aq$'AaxQQQQQQA}}a$sAq$d;KK%'  44[1t 1AAwqzR#]]40Q  11 :r cddlm}|j}tj||dd}|Dcgc]}dt |cxkrdksnn|}}t |\}}t dtt |D];}tt ||D]}t |||dt =t tt |D]}t d |d zz||ycc}w) Nr)r6r$ z Word Finder  )endz%d:r) nltk.corpusr6rshufflerr>printr)r6wordlistwrr9rr=s r word_finderrIvs!{{}H NN8~H#9aqCF'8b'89H9H%JD$ / 3t9 s47|$ 'A $q'!*# & '  G 3t9 ( eq1uotAw'(:s C<C<__main__)rK2ABCDEFGHIJKLMNOPQRSTUVWXYZ)rr rr-r>rI__name__rr r rOs:D&@F(( zMr