예제 #1
0
파일: test_pe.py 프로젝트: jpaeng/PE
def test_common():
    # variables
    ordered_list = list(range(-10, 10))
    prime_list_10 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

    # power_digit_sum
    common.power_digit_sum(2, 15) == 26

    # index_in_ordered_list
    assert common.index_in_ordered_list(-10, ordered_list) == ordered_list.index(-10)
    assert common.index_in_ordered_list( -1, ordered_list) == ordered_list.index(-1)
    assert common.index_in_ordered_list(  0, ordered_list) == ordered_list.index(0)
    assert common.index_in_ordered_list(  9, ordered_list) == ordered_list.index(9)
    assert common.index_in_ordered_list( 10, ordered_list) == -1
    assert common.index_in_ordered_list(-11, ordered_list) == -1

    # is_in_ordered_list
    assert common.is_in_ordered_list(-10, ordered_list)
    assert common.is_in_ordered_list( -1, ordered_list)
    assert common.is_in_ordered_list(  0, ordered_list)
    assert common.is_in_ordered_list(  9, ordered_list)
    assert common.is_in_ordered_list( 10, ordered_list) is False
    assert common.is_in_ordered_list(-11, ordered_list) is False

    assert common.str_permutation(11, '0123') == '1320'
    assert common.str_permutation(999999, '0123456789') == '2783915460'

    # get_factors
    assert common.get_factors(1) == [1]
    assert common.get_factors(16) == [1, 2, 4, 8, 16]

    # sieve_erathosthenes
    assert common.sieve_erathosthenes(30) == prime_list_10
    assert common.sieve_erathosthenes(30) != ordered_list
    assert common.sieve_erathosthenes2(30) == prime_list_10
    assert common.prime_list_mr(0, 30) == prime_list_10

    # get_prime_factors
    assert common.get_prime_factors(0, prime_list_10) == []
    assert common.get_prime_factors(2, prime_list_10) == [2]
    assert common.get_prime_factors(512, prime_list_10) == [2]
    assert common.get_prime_factors(60, prime_list_10) == [2, 3, 5]
    assert common.get_prime_factors(6469693230, prime_list_10) == prime_list_10
예제 #2
0
파일: p02x.py 프로젝트: jpaeng/PE
     p022_names_list = (file_ptr.read().replace('"', '')).split(',')
     file_ptr.close()
     print(alpha_list_score(p022_names_list))
 elif problem_num == 23:
     z_abund_list = abundant_list(100)
     print()
     print(z_abund_list)
     print(abundant_sum_list(40))
     print(non_abundant_sum_list(40))
     print('Sum of all non-abundant numbers below 40:', sum(non_abundant_sum_list(40)))
     # print('Sum of all non-abundant numbers below 28123:', sum(non_abundant_sum_list(28123)))
     z_abund_list = abundant_list(10000)
     print('Odd abundant numbers below 10000: ', [z for z in z_abund_list if z % 2])
 elif problem_num == 24:
     print()
     print(999999, common.str_permutation(999999, '0123456789'))
 elif problem_num == 25:
     print()
     for z in range(1, 5):
         print(fibonacci_greater_than(10**z))
     print(fibonacci_greater_than(10**999)[0])
 elif problem_num == 26:
     print()
     for z in range(1, 11):
         print(z, recurring_cycle(z))
     zlongest = 0
     zlongest_z = 1
     for z in range(1, 1000):
         zcycle_length = recurring_cycle(z)
         if zlongest < zcycle_length:
             zlongest = zcycle_length