示例#1
0
def check_fraction(n1,n2):
    d1 = mwmath.get_digits(n1)
    d2 = mwmath.get_digits(n2)
    if d1[1]==0:
        if d2[1]==0:
            return [1,1]
    
    init_frac = 1.0*n1/n2

    common = get_common_digit(n1,n2)
    if len(common)==0:
        return [1,1]
    
    [new_1,new_2,new_frac] = remove_common_digit(n1,n2,common[0])
    #print new_1
    #print new_2
    
    #print 'init:', init_frac
    #print 'new:', new_frac

    if init_frac==new_frac:
        print 'hit'
        print n1,' ',n2
        print new_1,' ',new_2
        return [new_1,new_2]
    else:
         return [1,1]
示例#2
0
def get_common_digit(n1,n2):
    d1 = mwmath.get_digits(n1)
    d2 = mwmath.get_digits(n2)

    common = []
    
    for digit in d1:
        if digit in d2:
            common.append(digit)

    return common
示例#3
0
def is_permute(a,b):
        if not len(str(a))==len(str(b)):
            return False
        
        b_dig = mwmath.get_digits(b)
        for dig in mwmath.get_digits(a):
                if dig in b_dig:
                        b_dig.remove(dig)
                else:
                        return False

        return True
示例#4
0
def is_permute(a, b):
    if not len(str(a)) == len(str(b)):
        return False

    b_dig = mwmath.get_digits(b)
    for dig in mwmath.get_digits(a):
        if dig in b_dig:
            b_dig.remove(dig)
        else:
            return False

    return True
示例#5
0
def find_truncatable_primes(prime_list):

    truncatable_count = 0
    trunc_sum = 0
    kk = 0
    while truncatable_count<11:
        new_p = prime_list[kk]
        if new_p<11:
            kk+=1
            continue

        digits = mwmath.get_digits(new_p)
        check = True

        if digits[0]==1 or digits[0]==9:
            check=False
        if new_p%10==1 or new_p%10==9:
            check=False
        for digit in digits:
            if (digit!=2) and (digit%2==0):
                check=False

        #try to truncate from rinth
        while check:
            if len(mwmath.get_digits(new_p))==1:
                break
            new_p = int(str(new_p)[1:])
            if not new_p in prime_list:
                check=False
    
        #truncate from left
        new_p = prime_list[kk]
        while check:
            if len(mwmath.get_digits(new_p))==1:
                break
            new_p = int(str(new_p)[:len(mwmath.get_digits(new_p))-1])
            if not new_p in prime_list:
                check=False

        new_p = prime_list[kk]
        if check:
            truncatable_count+=1
            trunc_sum+=new_p
            print "Found one: " +str(new_p)
    
        kk+=1

    return trunc_sum
示例#6
0
def find_truncatable_primes(prime_list):

    truncatable_count = 0
    trunc_sum = 0
    kk = 0
    while truncatable_count < 11:
        new_p = prime_list[kk]
        if new_p < 11:
            kk += 1
            continue

        digits = mwmath.get_digits(new_p)
        check = True

        if digits[0] == 1 or digits[0] == 9:
            check = False
        if new_p % 10 == 1 or new_p % 10 == 9:
            check = False
        for digit in digits:
            if (digit != 2) and (digit % 2 == 0):
                check = False

        #try to truncate from rinth
        while check:
            if len(mwmath.get_digits(new_p)) == 1:
                break
            new_p = int(str(new_p)[1:])
            if not new_p in prime_list:
                check = False

        #truncate from left
        new_p = prime_list[kk]
        while check:
            if len(mwmath.get_digits(new_p)) == 1:
                break
            new_p = int(str(new_p)[:len(mwmath.get_digits(new_p)) - 1])
            if not new_p in prime_list:
                check = False

        new_p = prime_list[kk]
        if check:
            truncatable_count += 1
            trunc_sum += new_p
            print "Found one: " + str(new_p)

        kk += 1

    return trunc_sum
示例#7
0
def get_next_term(n, fact_dict):
    d = mwmath.get_digits(n)

    s = 0
    for ii in d:
        s += fact_dict[ii]

    return s
示例#8
0
def get_next_term(n,fact_dict):
    d = mwmath.get_digits(n)

    s = 0
    for ii in d:
        s+=fact_dict[ii]

    return s
示例#9
0
def get_next_term(n):
    d = mwmath.get_digits(n)

    s = 0
    for ii in d:
        s+=ii**2

    return s
示例#10
0
def remove_common_digit(n1, n2, common):
    d1 = mwmath.get_digits(n1)
    d2 = mwmath.get_digits(n2)

    for digit in d1:
        if not int(digit) == common:
            new_1 = float(digit)

    for digit2 in d2:

        if not int(digit2) == common:
            new_2 = float(digit2)
            if new_2 == 0:
                return [new_1, new_2, 0]
    else:
        return [1, 0, 0]

    return [new_1, new_2, new_1 / new_2]
示例#11
0
def remove_common_digit(n1,n2,common):
    d1 = mwmath.get_digits(n1)
    d2 = mwmath.get_digits(n2)

    if d1[0]==common:
        new_1 = d1[1]
    else:
        new_1 = d1[0]

    if d2[0]==common:
        new_2 = d2[1]
    else:
        new_2 = d2[0]

    if new_2==0:
        return [1,0,0]
    else:
        return [new_1,new_2,1.0*new_1/new_2]
示例#12
0
def remove_common_digit(n1,n2,common):
    d1 = mwmath.get_digits(n1)
    d2 = mwmath.get_digits(n2)

    for digit in d1:
        if not int(digit)==common:
            new_1 = float(digit)

    for digit2 in d2:

        if not int(digit2)==common:
            new_2 = float(digit2)
            if new_2==0:
                return [new_1,new_2,0]
    else:
        return [1,0,0]
            
    return [new_1,new_2,new_1/new_2]
示例#13
0
def main():

    fact_sum = []

    for ii in range(3, 2903040):
        digits = mwmath.get_digits(ii)
        m_d = max(digits)
        if m_d < 4 and ii > 100:
            continue
        if m_d < 6 and ii > 10000:
            continue
        if m_d < 9 and ii > 1000000:
            continue
        if m_d < 8 and ii > 100000:
            continue

        if sum(map(mwmath.nr_factorial, digits)) == ii:
            fact_sum.append(ii)

    return sum(fact_sum)
示例#14
0
def main():

    fact_sum = []


    for ii in range(3,2903040):
        digits = mwmath.get_digits(ii)
        m_d = max(digits)
        if m_d<4 and ii>100:
            continue
        if m_d<6 and ii>10000:
            continue
        if m_d<9 and ii>1000000:
            continue
        if m_d<8 and ii>100000:
            continue
    
        if sum(map(mwmath.nr_factorial,digits))==ii:
            fact_sum.append(ii)

    return sum(fact_sum)
示例#15
0
def check_substring_properties(n):
    digits = mwmath.get_digits(n)

    prime_list = [2,3,5,7,11,13,17]
    if len(digits)==10:
        for ii in range(7,0,-1):
            d = 100*digits[ii]+10*digits[ii+1]+digits[ii+2]

            if d%prime_list[ii-1]==0:
                continue
            else:
                return False
    if len(digits)==9:
        for ii in range(6,-1,-1):
            d = 100*digits[ii]+10*digits[ii+1]+digits[ii+2]

            if d%prime_list[ii-1]==0:
                continue
            else:
                return False    

    return True
示例#16
0
def check_substring_properties(n):
    digits = mwmath.get_digits(n)

    prime_list = [2, 3, 5, 7, 11, 13, 17]
    if len(digits) == 10:
        for ii in range(7, 0, -1):
            d = 100 * digits[ii] + 10 * digits[ii + 1] + digits[ii + 2]

            if d % prime_list[ii - 1] == 0:
                continue
            else:
                return False
    if len(digits) == 9:
        for ii in range(6, -1, -1):
            d = 100 * digits[ii] + 10 * digits[ii + 1] + digits[ii + 2]

            if d % prime_list[ii - 1] == 0:
                continue
            else:
                return False

    return True
示例#17
0
n = 10000
potential_primes = [2, 3]
ii = 1
while 6 * ii <= (n):
    potential_primes.append(6 * ii - 1)
    potential_primes.append(6 * ii + 1)
    ii += 1

prime_list = []
for jj in potential_primes:
    if mwmath.is_prime(jj):
        prime_list.append(jj)

new_p = 37

digits = mwmath.get_digits(new_p)
check = True

for digit in digits:
    if (digit % 2 == 0):
        check = False
        print "Contains an even digit"

    #try to truncate from right
while check:
    if len(mwmath.get_digits(new_p)) == 1:
        break
    new_p = int(str(new_p)[1:])
    if not new_p in prime_list:
        print "Breaking " + str(new_p) + " is not prime"
        check = False
示例#18
0
def main():
    s = time.time()
    
    return [sum(mwmath.get_digits(mwmath.nr_factorial(100))),time.time()-s]
示例#19
0
def main():
    Fact = mwmath.nr_factorial(100)

    return sum(mwmath.get_digits(Fact))
示例#20
0
def main():
    s = time.time()

    return [sum(mwmath.get_digits(mwmath.nr_factorial(100))), time.time() - s]
示例#21
0
potential_primes=[2,3]
ii = 1
while 6*ii<=(n):
    potential_primes.append(6*ii-1)
    potential_primes.append(6*ii+1)
    ii+=1

prime_list=[]
for jj in potential_primes:
    if mwmath.is_prime(jj):
        prime_list.append(jj)


new_p = 37

digits = mwmath.get_digits(new_p)
check = True
    
for digit in digits:
    if (digit%2==0):
        check=False
        print "Contains an even digit"
        

    #try to truncate from right
while check:
    if len(mwmath.get_digits(new_p))==1:
        break
    new_p = int(str(new_p)[1:])
    if not new_p in prime_list:
        print "Breaking "+str(new_p)+" is not prime"
示例#22
0
def digit_sum(n):
    return sum(mwmath.get_digits(n))
示例#23
0
def digit_sum(n):
    return sum(mwmath.get_digits(n))