Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
akuazzam authored Nov 15, 2020
1 parent e4af2c8 commit 6346a40
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions MinRows.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions palindrome_checker.py
Original file line number Diff line number Diff line change
@@ -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))
16 changes: 16 additions & 0 deletions passcracker.py
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions permutation_checker.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6346a40

Please sign in to comment.