Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import sys
  2. import random
  3.  
  4. dict_path, n, m = sys.argv[1:4]
  5. n = int(n)
  6. m = int(m)
  7. words = list(map(str.rstrip, open(dict_path)))
  8. max_word_len = max(map(len, words))
  9. len_below = [[w for w in words if len(w) <= i] for i in range(max_word_len + 1)]
  10. print(m)
  11. print(n)
  12. lines = []
  13. for i in range(n):
  14.     line = list(' ' * m)
  15.     i = 0
  16.     while i < m:
  17.         ws = len_below[m - i] if m - i <= max_word_len else words
  18.         if ws:
  19.             word = random.choice(ws)
  20.             for j, c in enumerate(word):
  21.                 line[i + j] = c
  22.             i += len(word) + 1
  23.         else:
  24.             break
  25.     lines.append(line)
  26. cols = list(map(''.join, zip(*lines)))
  27. random.shuffle(cols)
  28. print('\n'.join(cols))
  29. print()
  30. print(dict_path)
  31. print()
  32. print('\n'.join(map(''.join, lines)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement