Beispiel #1
0
def run(exp):
    st = str(2**exp);   #Raise 2 to exp power and make a string of the number.
    m  = map(int, st);  #Turn digits into integers.
    s  = sum(m);        #Sum them.

    #Report completion.
    eulersupport.write_output(s);
def run():
    #Get the input file.
    f = eulersupport.get_input_file()

    #Initialize the matrix.
    matrix = []
    for l in f.readlines():
        l = l.replace("\n", "")
        matrix.append(map(int, l.split(" ")))

    greatest = -1
    #Perform the calculations.
    for i in xrange(len(matrix)):
        for j in xrange(len(matrix[i])):
            h = find_horizontal(matrix, i, j)
            v = find_vertical(matrix, i, j)
            d1 = find_diagonal1(matrix, i, j)
            d2 = find_diagonal2(matrix, i, j)

            curr = max([h, v, d1, d2])
            if (curr > greatest):
                greatest = curr

    #Print the results.
    eulersupport.write_output(greatest)
Beispiel #3
0
def run():
    #Get the input file.
    f = eulersupport.get_input_file();

    #Initialize the matrix.
    matrix = [];
    for l in f.readlines():
        l = l.replace("\n", "");
        matrix.append(map(int, l.split(" ")));
    
    greatest = -1;       
    #Perform the calculations.
    for i in xrange(len(matrix)):
        for j in xrange(len(matrix[i])):        
            h  = find_horizontal(matrix, i, j);
            v  = find_vertical(matrix, i, j);
            d1 = find_diagonal1(matrix, i, j);
            d2 = find_diagonal2(matrix, i, j);
            
            curr = max([h,v,d1,d2]);
            if(curr > greatest):
                greatest = curr;

    #Print the results.
    eulersupport.write_output(greatest);
Beispiel #4
0
def run(upperbound):
    number = str(
        sum(map(pow, xrange(1, upperbound + 1), xrange(1, upperbound + 1))))
    result = number[-10:]

    #Report Completion.
    eulersupport.write_output(result)
Beispiel #5
0
def run():
    lines  = eulersupport.get_input_file().readlines();  #List of numbers as Strings.
    m      = map(int, lines); #Map the numbers into ints.
    nstr   = str(sum(m));     #Sum them and transform it into a string.
    snstr  = nstr[:10];       #Get the first 10 digits.
    
    #Report completion.
    eulersupport.write_output(snstr);
Beispiel #6
0
def run():
    prime = (28433) * (2**7830457) + 1
    #Extract the last 10 digits of the number.
    prime_str = str(prime)
    last_ten = prime_str[len(prime_str) - 10:len(prime_str)]

    #Report Completion.
    eulersupport.write_output(last_ten)
Beispiel #7
0
def run(upperbound):
    result = -1
    factors = eulermath.prime_factors(upperbound)
    for factor in factors:
        if (factor[0] > result):
            result = factor[0]

    eulersupport.write_output(result)
Beispiel #8
0
def run(upperbound):    
    result = -1;
    factors = eulermath.prime_factors(upperbound);
    for factor in factors:
        if(factor[0] > result):
            result = factor[0];
     
    eulersupport.write_output(result);
Beispiel #9
0
def run():
    prime = (28433) * (2**7830457) + 1
    #Extract the last 10 digits of the number.
    prime_str = str(prime);
    last_ten  = prime_str[len(prime_str)-10 : len(prime_str)];
    
    #Report Completion.
    eulersupport.write_output(last_ten);
Beispiel #10
0
def run():
    result = 0;
    for i in range(0, 1000000):
        if(is_palindrome_2(i) and eulermath.is_palindrome(i)):
            print i;
            result += i;

    #Print the result.
    eulersupport.write_output(result);
def run():
    result = 0
    for i in range(0, 1000000):
        if (is_palindrome_2(i) and eulermath.is_palindrome(i)):
            print i
            result += i

    #Print the result.
    eulersupport.write_output(result)
Beispiel #12
0
def run(upperbound):
    result  = 0;    #Sum of all values evenly divisible by 5 and 3.
    for i in range(1, upperbound):
        #Is evenly divisible by the two numbers?
        if((i % 3 == 0) or (i % 5 == 0)):
            result += i;

    #Report Completion.
    eulersupport.write_output(result);
Beispiel #13
0
def run(upperbound):
    helper = eulermath.PrimesHelper();
    print "Starting find primes...";
    helper.find_all_primes_up_to_n(upperbound);
    print "Find primes done."
    result = sum(helper.get_primes());
    
    #Report completion.
    eulersupport.write_output(result);
def run(upperbound):
    helper = eulermath.PrimesHelper()
    print "Starting find primes..."
    helper.find_all_primes_up_to_n(upperbound)
    print "Find primes done."
    result = sum(helper.get_primes())

    #Report completion.
    eulersupport.write_output(result)
Beispiel #15
0
def run():
    #Find all numbers.
    find_all_abundant_numbers()

    #Sum of all numbers that cannot be writton.
    result = find_sum_cannot_be_written()

    #Report completion.
    eulersupport.write_output(result)
Beispiel #16
0
def run():
    result = -1;
    for i in eulermath.infinite_range(9, 2):
        if(not f(i)):
            result = i;
            break;

    print result;
    #Report Completion.
    eulersupport.write_output(result);
Beispiel #17
0
def run(upperbound):
    numbers = range(1, upperbound + 1); #All numbers up to upperbound. 
    
    sum_of_squares = sum(map(pow, numbers, [2] * (upperbound)));
    square_of_sums = sum(numbers) ** 2;
    
    result = (square_of_sums - sum_of_squares);
    
    #Report completion.
    eulersupport.write_output(result);
def run():
    result = -1
    for i in eulermath.infinite_range(9, 2):
        if (not f(i)):
            result = i
            break

    print result
    #Report Completion.
    eulersupport.write_output(result)
Beispiel #19
0
def run():
    count = 0;
    for n in xrange(1, 100 + 1):
        for r in range(1, n+1):
            a = nCr(n,r);
            if(a > 1000000):
                count += 1;

    #Print the result.
    eulersupport.write_output(count);
Beispiel #20
0
def run(upperbound):
    s = 0;  #Sum of all amicable numbers.
    for i in xrange(1, upperbound +1):
        # print i;
        if(eulermath.is_amicable(i)):
            eulersupport.log(i, "is amicable.");
            s += i;
    
    #Report completion.
    eulersupport.write_output(s);
Beispiel #21
0
def run(upperbound):
    result = 0
    #Sum of all values evenly divisible by 5 and 3.
    for i in range(1, upperbound):
        #Is evenly divisible by the two numbers?
        if ((i % 3 == 0) or (i % 5 == 0)):
            result += i

    #Report Completion.
    eulersupport.write_output(result)
Beispiel #22
0
def run(upperbound):
    #calculate the factorial of the number.
    f = eulermath.factorial(upperbound)
    #First turn the number into a string, next for each char turn it into a
    #int and return a list of the digits contained at number.
    m = map(int, str(f))
    #Sum all digits of number.
    s = sum(m)

    #Report completion.
    eulersupport.write_output(s)
Beispiel #23
0
def run(upperbound):
    s = 0
    #Sum of all amicable numbers.
    for i in xrange(1, upperbound + 1):
        # print i;
        if (eulermath.is_amicable(i)):
            eulersupport.log(i, "is amicable.")
            s += i

    #Report completion.
    eulersupport.write_output(s)
Beispiel #24
0
def run():
    result = 0

    for i in eulermath.permutations(list("1234567890")):
        str_i = eulersupport.list_to_str(i)
        int_i = int(str_i)
        if (eulermath.is_strictly_pandigital(int_i, 0, 9) and f(int_i)):
            print str_i
            result += 1

    eulersupport.write_output(result)
Beispiel #25
0
def run():
    result = 0;

    for i in eulermath.permutations(list("1234567890")):
        str_i = eulersupport.list_to_str(i);
        int_i = int(str_i);
        if(eulermath.is_strictly_pandigital(int_i, 0, 9) and f(int_i)):
            print str_i;
            result += 1;

    eulersupport.write_output(result);
def run():
    maximum = 0
    for a in xrange(1, 100):
        for b in xrange(1, 100):
            print a, b
            curr_sum = sum(map(int, str(pow(a, b))))
            if (curr_sum > maximum):
                maximum = curr_sum

    #Report Completion.
    eulersupport.write_output(maximum)
Beispiel #27
0
def run(upperbound):
    #calculate the factorial of the number.
    f = eulermath.factorial(upperbound); 
    #First turn the number into a string, next for each char turn it into a 
    #int and return a list of the digits contained at number.
    m = map(int, str(f)); 
    #Sum all digits of number.
    s = sum(m);

    #Report completion.
    eulersupport.write_output(s);
Beispiel #28
0
def run(upperbound):
    for m in xrange(1, 1000):
        for n in xrange(1, m):
            a = 2 * m * n
            b = m**2 - n**2
            c = m**2 + n**2
            #Is the triplet the we wants?
            if (a + b + c == upperbound):
                #Report Completion
                eulersupport.write_output(a * b * c)
                return
Beispiel #29
0
def run(upperbound):
    for m in xrange(1, 1000):
        for n in xrange(1, m):
            a = 2*m*n;
            b = m**2 - n**2;
            c = m**2 + n**2;
            #Is the triplet the we wants?
            if(a + b + c == upperbound): 
                #Report Completion
                eulersupport.write_output(a * b * c);
                return; #Go out we are done.
Beispiel #30
0
def run():
    maximum = 0;
    for a in xrange(1, 100):
        for b in xrange(1, 100):
            print a, b;
            curr_sum = sum(map(int, str(pow(a,b))));        
            if(curr_sum > maximum):
                maximum = curr_sum;
    
    #Report Completion.
    eulersupport.write_output(maximum);
def run():
    lines = eulersupport.get_input_file().readlines()
    #List of numbers as Strings.
    m = map(int, lines)
    #Map the numbers into ints.
    nstr = str(sum(m))
    #Sum them and transform it into a string.
    snstr = nstr[:10]
    #Get the first 10 digits.

    #Report completion.
    eulersupport.write_output(snstr)
Beispiel #32
0
def run(upperbound):    
    result = 0; #Sum of even-valued elements.
    for n in eulermath.fibonacci(1, 2):        
        #if is even add it to result.
        if(n % 2 == 0):
            result += n;
        
        if(n > upperbound):
            break;

    #Report Completion.
    eulersupport.write_output(result);
Beispiel #33
0
def run():
    for j in eulermath.infinite_range(1):
        Pj = eulermath.pentagonal_number(j);

        for k in xrange(1, j):
            Pk = eulermath.pentagonal_number(k);
            s = Pj + Pk;
            d = Pj - Pk;

            if(eulermath.is_pentagonal_number(s) and eulermath.is_pentagonal_number(d)):
                eulersupport.write_output(d);
                return;
Beispiel #34
0
def run(p):
    result 	= 0; 
    index  	= 2;    
    upper_bound = int("9" * (p+1));

    while(index < upper_bound):        
        if(f(index, p)):
            result += index;	                    
        index += 1;

    #Print the result.
    eulersupport.write_output(result);
Beispiel #35
0
def run(lowerbound, upperbound):
    a = lowerbound;  #Base
    b = upperbound;  #Exp
    l = set();       #All distinct terms.
    
    for i in range(lowerbound, upperbound+1):
        for j in range(lowerbound, upperbound+1):
            n = i ** j;            
            l.add(n);

    #Report completion.
    eulersupport.write_output(len(l));
Beispiel #36
0
def run():
    eulermath.PrimesHelper().find_all_primes_up_to_n(7)

    list_of_primes = []
    while len(list_of_primes) != 11:
        prime = eulermath.PrimesHelper().find_next_prime()
        if fr(prime) and fl(prime):
            list_of_primes.append(prime)
            print list_of_primes

    result = sum(list_of_primes)
    eulersupport.write_output(result)
def run(p):
    result = 0
    index = 2
    upper_bound = int("9" * (p + 1))

    while (index < upper_bound):
        if (f(index, p)):
            result += index
        index += 1

    #Print the result.
    eulersupport.write_output(result)
Beispiel #38
0
def run():
    for j in eulermath.infinite_range(1):
        Pj = eulermath.pentagonal_number(j)

        for k in xrange(1, j):
            Pk = eulermath.pentagonal_number(k)
            s = Pj + Pk
            d = Pj - Pk

            if eulermath.is_pentagonal_number(s) and eulermath.is_pentagonal_number(d):
                eulersupport.write_output(d)
                return
Beispiel #39
0
def run(upperbound):
    count_89    = 0;
    count_1     = 0;
    count_other = 0;

    for i in xrange(0, upperbound):
        chain = find_chain(i);

        if  (chain[0] == 89): count_89 += 1;
        elif(chain[0] ==  1): count_1  += 1;

    #Report Completion.
    eulersupport.write_output(count_89);
Beispiel #40
0
def run():
    m = map(str, range(1, 1000001)); #Create the fraction.
    s = str().join(m);               #Turn it into one string.

    prod = 1;
    for pwr in xrange(0,7):       #iterate for the power
        index = pow(10, pwr);     #Calculate the index.
        digit = int(s[index -1]); #Get the digit.
        print index, digit
        prod *= digit ;

    #Print the result.
    eulersupport.write_output(prod);
Beispiel #41
0
def run(upperbound):
    count_89 = 0
    count_1 = 0
    count_other = 0

    for i in xrange(0, upperbound):
        chain = find_chain(i)

        if (chain[0] == 89): count_89 += 1
        elif (chain[0] == 1): count_1 += 1

    #Report Completion.
    eulersupport.write_output(count_89)
Beispiel #42
0
def run(upperbound):
    size  = 0; #How many digits the element has.
    index = 0; #Index of the target number in the fibonacci sequence.

    for n in eulermath.fibonacci(1, 1):
        size   = len(str(n));  
        index += 1;

        if(size == upperbound):
            break;

    #Report completion.
    eulersupport.write_output(index);
def run(upperbound):
    result = 0
    #Sum of even-valued elements.
    for n in eulermath.fibonacci(1, 2):
        #if is even add it to result.
        if (n % 2 == 0):
            result += n

        if (n > upperbound):
            break

    #Report Completion.
    eulersupport.write_output(result)
Beispiel #44
0
def run(upperbound):
    l = [];
    for i in range(1, upperbound + 1):
        list_of_results = f(i); #Get the results for the i.

        if(len(list_of_results) != 0):
            print i, list_of_results;
            l += [[len(list_of_results), i]];

    l.sort();

    #Print the result.
    eulersupport.write_output(l[-1]);
Beispiel #45
0
def run(upperbound):
    maxSize = 0; #Greatest sequence.
    n       = 0; #The number the produces the greatest sequence.

    for i in range(1, upperbound + 1):
        print i;
        size = collatz(i);  #Get the size of the sequence.
        if(size > maxSize):
            maxSize = size;
            n = i;

    #Print the result.
    eulersupport.write_output(n);
def run(exp):
    max_value = (10 ** exp) -1;  #Inclusive upper bound of values.
    max_palin = 0;               #Greater palindrome found.
    
    #Search backwards.
    for i in range(max_value, 1, -1):
        for j in range(i, 1, -1):                    
            #The number is palindrome and is greater that 
            #current max palindrome?
            if((i * j) > max_palin and eulermath.is_palindrome(i * j)):
                max_palin = (i * j);

    #Print the result.
    eulersupport.write_output(max_palin);
def run(upperbound):
    l = []
    for i in range(1, upperbound + 1):
        list_of_results = f(i)
        #Get the results for the i.

        if (len(list_of_results) != 0):
            print i, list_of_results
            l += [[len(list_of_results), i]]

    l.sort()

    #Print the result.
    eulersupport.write_output(l[-1])
def run(upperbound):
    size = 0
    #How many digits the element has.
    index = 0
    #Index of the target number in the fibonacci sequence.

    for n in eulermath.fibonacci(1, 1):
        size = len(str(n))
        index += 1

        if (size == upperbound):
            break

    #Report completion.
    eulersupport.write_output(index)
def run(upperbound):
    maxSize = 0
    #Greatest sequence.
    n = 0
    #The number the produces the greatest sequence.

    for i in range(1, upperbound + 1):
        print i
        size = collatz(i)
        #Get the size of the sequence.
        if (size > maxSize):
            maxSize = size
            n = i

    #Print the result.
    eulersupport.write_output(n)
Beispiel #50
0
def run(upperbound):
    
    result = 0;
    i      = 1;
    while(True):
        n     = eulermath.triangle_number(i);
        count = eulermath.factors_count(n);
        
	eulersupport.log(n, count);
        
        if(count > upperbound):
            result = n;
            break;
            
        i += 1;
    #Report Completion.
    eulersupport.write_output(result);
def run():
    index = 3
    result = 0

    while (index < 10**7):
        list_d = eulermath.list_of_digits(index)
        list_factorial_d = map(eulermath.factorial, list_d)
        sum_of_factorials = sum(list_factorial_d)

        if (sum_of_factorials == index):
            print index
            result += index

        index += 1

    # Print the result.
    eulersupport.write_output(result)
Beispiel #52
0
def run():
    upper_bound = 10000
    count = 0
    for i in xrange(1, upper_bound):
        for exp in xrange(1, upper_bound):
            n = i**exp
            digits = len(str(n))
            print "exp:    " + str(exp)
            print "digits: " + str(digits)

            if (digits == exp):
                print str(i) + "**" + str(exp) + " = " + str(n)
                count += 1
            elif (digits > exp):
                break

    #Report Completion.
    eulersupport.write_output(count)
Beispiel #53
0
def run(upperbound):
    list_of_primes = [];

    #Find all the primes.
    eulermath.PrimesHelper().find_all_primes_up_to_n(upperbound);
    for prime in eulermath.PrimesHelper().get_primes():
        digits = list(str(prime));

        #Check if all permutations are prime.
        perms = eulermath.all_rotations(digits);
        perms = [int(eulersupport.list_to_str(perm)) for perm in perms];

        all_perms_are_prime = all(eulermath.PrimesHelper().is_prime(x) for x in perms);
        print prime, "-", perms, all_perms_are_prime;

        #Add to list of primes
        if(all_perms_are_prime):
            list_of_primes.append(prime);

    eulersupport.write_output(len(list_of_primes));
def run(lowerbound, upperbound):

    result = {
        "a": 0,
        "b": 0,
        "count": 0
    }

    #Try all formulas.
    for a in xrange(lowerbound + 1, upperbound):
        for b in xrange(lowerbound + 1, upperbound):
            count = countPrimes(a, b)
            if (count != 0):
                if (count > result["count"]):
                    result["a"] = a
                    result["b"] = b
                    result["count"] = count
                    print result

    eulersupport.write_output(result["a"] * result["b"])
Beispiel #55
0
def run():
    factors_count = 4
    consecutive_count = 4
    consecutive_list = []
    result = None

    for i in eulermath.infinite_range(0):
        print i
        factors = eulermath.prime_factors(i)

        if (len(factors) == factors_count):
            consecutive_list.append(i)
        else:
            consecutive_list = []

        if (len(consecutive_list) == consecutive_count):
            result = consecutive_list[0]
            break

    eulersupport.write_output(result)
Beispiel #56
0
def run():
    list_of_pandigitals = [];
    upperbound = 999999 + 1;

    for a in xrange(2, upperbound):
        for b in xrange(2, a):
            #Create a concatenated product of a by (1...n)
            con_prod = concatenated_product(a, b);
            #We reach a number that is bigger than 9 digits.
            #has no meaning to keeping searching because it'll not
            #be a pandigital number.
            if(len(con_prod) > 9): break;


            if(eulermath.is_strictly_pandigital(con_prod, 1, 9)):
                list_of_pandigitals += [con_prod];

    list_of_pandigitals.sort();
    result = list_of_pandigitals[len(list_of_pandigitals)-1];

    #Print the result.
    eulersupport.write_output(result);