From 733f93718a8cbd678b0f5af84381e3e32a02684a Mon Sep 17 00:00:00 2001 From: evalevanto Date: Wed, 23 May 2018 03:45:58 +0300 Subject: [PATCH] My submission --- division.py | 16 ++++++++++++++++ unique.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 division.py create mode 100644 unique.py diff --git a/division.py b/division.py new file mode 100644 index 0000000..c75736a --- /dev/null +++ b/division.py @@ -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) \ No newline at end of file diff --git a/unique.py b/unique.py new file mode 100644 index 0000000..53a2b52 --- /dev/null +++ b/unique.py @@ -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() + \ No newline at end of file