diff --git a/MinRows.py b/MinRows.py new file mode 100644 index 0000000..3ae6ab9 --- /dev/null +++ b/MinRows.py @@ -0,0 +1,13 @@ +def minRows (hs): + rowMins = [-1 for i in range (len (hs))] + rowCount = 0 + for num in hs: + for i in range (len (rowMins)): + if (rowMins[i] == -1): + rowMins[i] = num + rowCount +=1 + break + elif (rowMins[i] > num): + rowMins[i] = num + break + return rowCount diff --git a/palindrome_checker.py b/palindrome_checker.py new file mode 100644 index 0000000..44c5c0a --- /dev/null +++ b/palindrome_checker.py @@ -0,0 +1,15 @@ +''' +Following function checks if a word is a palindrome +Takes in user input +''' +def isPalindromic (word): + for i in range (0, len (word) // 2): + if (word[i].lower() != word[len(word) - 1 - i].lower()): + return False + return True +word = input("Enter a word you want to check: ") + +if (isPalindromic (word)): + print ("{} is a planindrome!".format(word)) +else: + print ("{} is not a palindrome".format(word)) \ No newline at end of file diff --git a/passcracker.py b/passcracker.py new file mode 100644 index 0000000..8bdc778 --- /dev/null +++ b/passcracker.py @@ -0,0 +1,16 @@ +''' +following code prints out all the possilble alphabetic combination for string length of n +characters are limited to a-z for now +''' + +def print_all_combs (n): + def print_combs_recur (str): + if (len (str) == n): + print (str) + else: + for i in range (0, 26): + print_combs_recur (str + chr (ord ('a') + i)) + print_combs_recur ("") + +# print all the possible 4 letter words using [a-z] +print_all_combs (4) diff --git a/permutation_checker.py b/permutation_checker.py new file mode 100644 index 0000000..f750d0a --- /dev/null +++ b/permutation_checker.py @@ -0,0 +1,32 @@ +''' +Following code checks whether or not +two strings are permutaitons of one another +Not case sensetive +''' + +def arePerms (str1, str2): + if (len (str1) != len (str2)): + return False + # Create a histogram of str1 and cancel it out using str2 + # If there are any left overs, not permuations of each other + histogram = [0 for i in range (0, 26)] + + for i in range (0, len (str1)): + # creating a histogram for how many times each letter in str1 appears + # subtracting 97 to normalize characters by taking the value of 'a' on each character + # decrease each count of str2 + histogram[ord(str1[i].lower()) - 97] +=1 + histogram[ord(str2[i].lower()) - 97] -= 1 + + #check if there are any leftovers + for count in histogram: + if count != 0: + return False + return True + +#Tests +print(arePerms ("abc", "cba")) #True +print(arePerms ("lol", "llz")) #False +print(arePerms ("ABcd", "cBaD")) #True +print(arePerms ("", "")) #True +print(arePerms ("oofdf", "oofd")) #False \ No newline at end of file