← coderbyte_practice

the medium problem set wip

fc580614c73230b209023a1557492d412661d643 · ovidiucs · May 6, 2015 20:37

+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
diff --git a/medium/01-prime.time.py b/medium/01-prime.time.py
index e69de29..559d660 100644
--- a/medium/01-prime.time.py
+++ b/medium/01-prime.time.py
@@ -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. 
+"""
diff --git a/medium/02-run-length.py b/medium/02-run-length.py
index e69de29..44b2184 100644
--- a/medium/02-run-length.py
+++ b/medium/02-run-length.py
@@ -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())           
+
diff --git a/medium/03-prime-mover.py b/medium/03-prime-mover.py
index e69de29..a864fa8 100644
--- a/medium/03-prime-mover.py
+++ b/medium/03-prime-mover.py
@@ -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())           
+
diff --git a/medium/04-palindrome-two.py b/medium/04-palindrome-two.py
new file mode 100644
index 0000000..f24d184
--- /dev/null
+++ b/medium/04-palindrome-two.py
@@ -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())        
+
+
diff --git a/medium/05-division.py b/medium/05-division.py
new file mode 100644
index 0000000..b8cfaa7
--- /dev/null
+++ b/medium/05-division.py
@@ -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
diff --git a/medium/06-string-scramble.py b/medium/06-string-scramble.py
new file mode 100644
index 0000000..12fe90b
--- /dev/null
+++ b/medium/06-string-scramble.py
@@ -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