Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

def division(dividend, divider):
QUOTIENT = 0
while (dividend >= divider):
QUOTIENT += 1
dividend -= divider

print QUOTIENT
print ("Remainder: %d"%(dividend))



if __name__ == "__main__":
DIVIDEND = int(input("Enter your number: "))
DIVIDER = int(input("Divide your number by: "))
division(DIVIDEND, DIVIDER)
47 changes: 47 additions & 0 deletions unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

def nsquared(word):
# O(n^2): Nested for loops will achieve this complexity
for i, char in enumerate(word):
#Compare each character in the string to all succeeding characters.
for index in range(i+1, len(word)):
if (char == word[index]):
return "Not distinct"
return "Distinct characters"


# O(nlogn): Traverse a list linearly.
def nlogn(word):
# Sort the characters in the string in ascending order;
word = sorted(word)
compare = None
for char in word:
# compare one character to the next.
if (char == compare):
return "Not distinct"
compare = char
return "Distinct characters"


#O(n)
def nnotation(word):
#Create a set from the list of chars
distinctchars = set(word)
#Compare their lengths
if (len(word) == len(distinctchars)):
return "Distinct characters"
return "Not distinct"


##test function##
def test():
stringfunc = [nsquared, nlogn, nnotation]
tries = [("Programming", "Not distinct"), ("Talking", "Distinct characters")]
for func in stringfunc:
for arg, result in tries:
assert func(arg) == result



if __name__ == "__main__":
test()