Experiments with Knuth's 5,757 five letter words. https://charlesreid1.com/wiki/Five_Letter_Words
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
555B

  1. """
  2. distinct.py
  3. Donald Knuth, Art of Computer Programming, Volume 4 Facsimile 0
  4. Exercise #27
  5. How many SGB words contain exactly k distinct letters, for 1 <= k <= 5?
  6. """
  7. from get_words import get_words
  8. if __name__=="__main__":
  9. words = get_words()
  10. lengths = [[] for i in range(5+1)]
  11. for word in words:
  12. k = len(set(word))
  13. lengths[k].append(word)
  14. for i in range(1,5+1):
  15. print("-"*40)
  16. print("Number of words with {0:d} letters: {1:d}".format(i, len(lengths[i])))
  17. print(", ".join(lengths[i][0:5]))