Ad
Code
Diff
  • from math import sqrt
    
    #Same but with some memoization, better if you need to check some numbers more than once
    def prime(x, cache={}): 
        if x not in cache:
            if x <= 1:
                cache[x]= False
                return False
            for i in range(2,int(sqrt(x))+1):
                if x % i is 0:
                    cache[x] = False
                    return False
            cache[x] = True        
        return cache[x]
    • from math import sqrt
    • #Same but with some memoization, better if you need to check some numbers more than once
    • def prime(x, cache={}):
    • if x not in cache:
    • if x <= 1:
    • cache[x]= False
    • return False
    • for i in range(2,int(sqrt(x))):
    • for i in range(2,int(sqrt(x))+1):
    • if x % i is 0:
    • cache[x] = False
    • return False
    • cache[x] = True
    • return cache[x]
Code
Diff
  • def decrypt(code,amount):
        word = ""
        for i in code:
            if i==" ":
                word+=" "
                continue
            tmp = ord(i)-amount
            if tmp<65:
                tmp+=26
            word+=chr(tmp)
        return word
    • def decrypt(code,amount):
    • #place code here
    • let="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    • word = ""
    • x=0
    • for c in range(0,len(code)):
    • for i in range (0,len(let)):
    • if code[c] == " ":
    • word+=" "
    • break
    • elif code[c] == let[i]:
    • x=i
    • x-=amount
    • if x < 0:
    • x+=26
    • word+=let[x]
    • break
    • for i in code:
    • if i==" ":
    • word+=" "
    • continue
    • tmp = ord(i)-amount
    • if tmp<65:
    • tmp+=26
    • word+=chr(tmp)
    • return word