Created
February 3, 2021 15:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output for this script: