Added isPandigital function

This commit is contained in:
2021-10-11 12:57:43 -04:00
parent 4a79343766
commit 8dbb52db85
2 changed files with 60 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
#Python/pyClasses/StringAlgorithms.py
#Matthew Ellison
# Created: 07-21-21
#Modified: 07-21-21
#Modified: 10-11-21
#This file contains my library of string functions
"""
Copyright (C) 2021 Matthew Ellison
@@ -59,3 +59,24 @@ def isPalindrome(str: str) -> bool:
return True
else:
return False
#Returns true if the string passed to it is a pandigital
def isPandigitalFull(numStr: str, bottom: int, top: int) -> bool:
#Return false if top < bottom
if(top < bottom):
return False
#Return false if the wrong number of characters are in the string
if(len(numStr) != (top - bottom + 1)):
return False
#Make sure that all of the needed characters are in the string exactly one time
for cnt in range(bottom, top):
#Make sure there is exactly one of this number contained in the string
if(numStr.count(str(cnt)) != 1):
return False
#If the function has reached this part it has passed all of the falsifying tests
return True
def isPandigital(str: str) -> bool:
return isPandigitalFull(str, 1, 9)