Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created February 3, 2021 15:13
Show Gist options
  • Save chand1012/d0fec38d72f39b17bb80cee27896f95e to your computer and use it in GitHub Desktop.
Save chand1012/d0fec38d72f39b17bb80cee27896f95e to your computer and use it in GitHub Desktop.
Gets the number of permutations for alphanumeric ASCII characters in the range of 5 thought 12, totalled.
import string
# this part is from here: https://www.geeksforgeeks.org/program-to-calculate-the-value-of-npr/
# START Geeksforgeeks snippet
import math
def fact(n):
if (n <= 1):
return 1
return n * fact(n - 1)
def nPr(n, r):
return math.floor(fact(n) /
fact(n - r))
# END Geeksforgeeks snippet
choices = string.ascii_letters + string.digits
print('Character choices: ' + choices)
print('-' * 20)
n = len(choices)
rs = range(5, 12, 1)
total = 0
for r in rs:
x = nPr(n, r)
print(f'{n} choose {r}: {x}')
total += x
print('-'*20)
print(f'Total combinations: {total}')
@chand1012
Copy link
Author

Output for this script:

Character choices: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
--------------------
62 choose 5: 776520240
62 choose 6: 44261653680
62 choose 7: 2478652606080
62 choose 8: 136325893334400
62 choose 9: 7361598240057600
62 choose 10: 390164706723052800
62 choose 11: 20288564749598744576
--------------------
Total combinations: 20686229904145969376

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment