the medium problem set wip
+100 · 6 files changed
-
medium/01-prime.time.py+17 −0 -
medium/02-run-length.py+27 −0 -
medium/03-prime-mover.py+21 −0 -
medium/04-palindrome-two.py+12 −0 -
medium/05-division.py+12 −0 -
medium/06-string-scramble.py+11 −0
@@ -0,0 +1,17 @@ +def PrimeTime(num): + i = 2 + if num < 2: + return 'false' + while i < num: + if num % i == 0: + return 'false' + else: + i += 1 + return 'true' + +# keep this function call here +# to see how to enter arguments in Python scroll down +print PrimeTime(raw_input()) +""" +Have the function PrimeTime(num) take the num parameter being passed and return the string true if the parameter is a prime number, otherwise return the string false. The range will be between 1 and 2^16. +""" @@ -0,0 +1,27 @@ +def RunLength(str): + di = list(str) + ltst = [] + ct = 1 + while len(di) > 0: + try: + if di[0] == di[1]: + ct += 1 + else: + ltst.append(ct) + ltst.append(di[0]) + ct = 1 + except: + IndexError + del di[0] + + ltst.append(ct) + ltst.append(str[-1:]) + return "".join("{0}".format(n) for n in ltst) + + + + +# keep this function call here +# to see how to enter arguments in Python scroll down +print RunLength(raw_input()) + @@ -0,0 +1,21 @@ +def PrimeMover(num): + n = 0 + for i in range(1,10000): + if checkPrime(i): + if n < num: + n += 1 + else: + return i + break + +def checkPrime(z): + + for j in range(2, z): + if (z % j) == 0: + return False + return True + +# keep this function call here +# to see how to enter arguments in Python scroll down +print PrimeMover(raw_input()) + @@ -0,0 +1,12 @@ +def PalindromeTwo(str): + strg = ''.join(x for x in str.lower() if x.isalnum()) + if strg[::-1] == strg: + return 'true' + else: + return 'false' + +# keep this function call here +# to see how to enter arguments in Python scroll down +print PalindromeTwo(raw_input()) + + @@ -0,0 +1,12 @@ +def Division(num1,num2): + + while num2: + num1, num2 = num2, num1%num2 + return num1 + + + +# keep this function call here +# to see how to enter arguments in Python scroll down +print Division(raw_input()) +# i stole this from gcd tbh @@ -0,0 +1,11 @@ +def StringScramble(str1,str2): + + if set(str1) == set(str2): + return 'true' + return'false' + +# keep this function call here +# to see how to enter arguments in Python scroll down +print StringScramble(raw_input()) + +# not working