Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created June 9, 2011 04:19
Show Gist options
  • Save lxneng/1016051 to your computer and use it in GitHub Desktop.
Save lxneng/1016051 to your computer and use it in GitHub Desktop.
>>> import random
>>> ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 4))
'eKq1'
>>> # 62!/(62-4)! = 13 388 280
>>> # (62 !) / ((62 - 3) !) = 226 920
>>> # (62 !) / ((62 - 4) !) = 13 388 280
>>> def factorial(n):
... return reduce(lambda x,y: x*y, range(1,n+1))
...
...
>>> def p(m,n):
... """m!/(m-n)!"""
... return factorial(m)/factorial(m-n)
...
...
>>> p(62,4)
13388280L
>>> p(62,3)
226920L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment