开发者

calculating number of permutations (I guess)

开发者 https://www.devze.com 2023-04-01 21:36 出处:网络
I can generate word using 2 letters only, lets say \'k\' and \'e\'. Length of word is from 5 - 35 characters. Each letter and len of the word are randomly chosen with rand(). Can someone tell me how m

I can generate word using 2 letters only, lets say 'k' and 'e'. Length of word is from 5 - 35 characters. Each letter and len of the word are randomly chosen with rand(). Can someone tell me how much possible unique words I can produce. Thanks.

PS are these called permutations or开发者_如何学运维 combinations?


Permutations: order matters (your case) Combinations: order does not matter, i.e. "ke" == "ek"

N = 2^5 + 2^6 + ... 2^34 + 2^35

This is a finite-length geometric series, and Wolfram Alpha tells us: Sum[2^k, {k, 5, 35}] 68719476704 68,719,476,704 == some 69 billion


For each word of length N: there are 2 choices for each letter, thus there are 2n possible words. Adding up these values for all word lengths from 5 to 35:

>>> sum(2**n for n in range(5,36))
68719476704L
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号