示例#1
0
文件: prob35.py 项目: bsterrett/euler
def generate_rotated_numbers(list):
    if len(list) > 0:
        permutations = [list_as_number(list)]
        for i in range(1,len(list)):
            number = list_as_number(rotate_list_left(list,i))
            permutations.append(number)
        return permutations
    else:
        return []
示例#2
0
文件: prob35.py 项目: bsterrett/euler
def check_rotational_prime(list):
    number = list_as_number(list)
    if len(list) > 0:
        checked_dict[number] = True
        if check_primality_dyn(number,upper_bound):
            for i in range(1,len(list)):
                number = list_as_number(rotate_list_left(list,i))
                checked_dict[number] = True
                if not check_primality_dyn(number,upper_bound):
                    return False
            return True
        else:
            return False
    else:
        return False
示例#3
0
文件: prob43.py 项目: bsterrett/euler
def main():
    primes_list = [2, 3, 5, 7, 11, 13, 17]
    permutations_list = get_digit_permutations_as_list(1234567890)
    sum = 0
    for permutation in permutations_list:
        number = list_as_number(permutation)
        try:
            for i in range(1, len(permutation) - 2):
                if list_as_number(permutation[i : i + 3]) % primes_list[i - 1] != 0:

                    raise Found
            print "found one!", number
            sum += number
        except Found:
            pass
    print "Sum: ", sum
示例#4
0
文件: prob79.py 项目: bsterrett/euler
if __name__ == '__main__':

    keylog = [319,680,180,690,129,620,762,689,762,318,368,710,720,710,629,168,\
    160,689,716,731,736,729,316,729,729,710,769,290,719,680,318,389,162,289,162,\
    718,729,319,790,680,890,362,319,760,316,729,380,319,728,716]

    key = []
    try:
        while(True):
            fixed = len(keylog)
            for attempt in keylog:
                list = number_as_list(attempt)
                index = [-1,-1,-1]
                for d in range(0,len(list)):
                    digit = list[d]
                    if key.count(digit) == 0:
                        key.append(digit)
                        index[d] = key.index(digit)
                    else:
                        index[d] = key.index(digit)
                for i in range(1,len(list)):
                    if index[i] < index[i-1]:
                        digit = list[i]
                        key.remove(digit)
                        key.insert(index[i-1],digit)
                        fixed -= 1
            if fixed == len(keylog): raise Found
    except Found:
        print "Shortest key: ", list_as_number(key)
        exit(0)
示例#5
0
文件: prob38.py 项目: bsterrett/euler
#!python
from pelib import number_as_list, list_as_number
from pelib import check_1_9_pandigital as check_pandigital
    
if __name__ == '__main__':        
    best_starting_number = -1
    best_pandigital = -1
    number = 9876
    
    while(number > 0):
        number -= 1
        list = number_as_list(number)
        factor = 2
        while(len(list) < 9):
            list += number_as_list(number*factor)
            factor += 1 
        if check_pandigital(list) and factor >= 3:
            pand_number = list_as_number(list)
            if pand_number > best_pandigital:
                best_pandigital = pand_number
                best_starting_number = number
    print "Largest pandigital: ", best_pandigital
    exit(0)
示例#6
0
文件: prob33.py 项目: bsterrett/euler
            
    numer_matches = []
    denom_matches = []
    for numer in range(lower_bound,upper_bound):
        for denom in range(lower_bound,upper_bound):
            if numer < denom:
                # fractions under consideration are all less than 1
                numer_list = number_as_list(numer)
                denom_list = number_as_list(denom)
                for digit in range(1,10):
                    # skipping over removing zeros because they are "trivial" solutions
                    [numer_success, numer_new_list] = try_remove(numer_list, digit)
                    [denom_success, denom_new_list] = try_remove(denom_list, digit)
                    if numer_success and denom_success:
                        # this means a digit was removed from the numerator AND the demoninator
                        if denom_new_list != [0]:
                            # make sure denominator isnt just a 0
                            if float(numer)/denom == float(list_as_number(numer_new_list))/list_as_number(denom_new_list):
                                numer_matches.append(numer_new_list[0])
                                denom_matches.append(denom_new_list[0])

    numer = 1
    denom = 1
    for i in range(0,len(numer_matches)):
        numer *= numer_matches[i]
        denom *= denom_matches[i]
        
    print "Value of denominator: ", Fraction(numer, denom).denominator
    
    exit(0)