Skip to content

Instantly share code, notes, and snippets.

@JohnTroony
Last active September 27, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnTroony/80d8d6809520f43632d24e7717520e30 to your computer and use it in GitHub Desktop.
Save JohnTroony/80d8d6809520f43632d24e7717520e30 to your computer and use it in GitHub Desktop.
Permutation of numbers with repeating.
#!/usr/bin/python
# John (Troon) Ombagi
# jayombagi@gmail.com
# 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