Last active
September 27, 2019 12:12
-
-
Save JohnTroony/80d8d6809520f43632d24e7717520e30 to your computer and use it in GitHub Desktop.
Permutation of numbers with repeating.
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
#!/usr/bin/python | |
# John (Troon) Ombagi | |
# [email protected] | |
# PR(n, k) = n^k ----> Permutation with repetition. | |
import itertools | |
import sys | |
def PR(n, k): | |
for permutation in itertools.product(xrange(n), repeat=k): | |
print(''.join(map(str, permutation))) | |
if len(sys.argv) == 3: | |
n = int(sys.argv[1]) | |
k = int(sys.argv[2]) | |
if n >= k: | |
PR(n, k) | |
else: | |
print("[-] n should be greater or equal to k.") | |
print(" Example : perm_repeat.py 10 4") | |
else: | |
print("[-] Please supply two arguments : n and k.") | |
print(" Example : perm_repeat.py 10 5") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment